自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

C#Windows服務(wù)程序之安裝項目

開發(fā) 后端
C#Windows服務(wù)程序之安裝項目主要向你介紹如何創(chuàng)建Windows服務(wù)應(yīng)用程序(以前稱為"NT 服務(wù)"的一個安裝項目,希望對你了解C#Windows服務(wù)程序有所幫助。

C#Windows服務(wù)程序之安裝項目的由來:本文介紹如何創(chuàng)建Windows 服務(wù)應(yīng)用程序(以前稱為"NT 服務(wù)")的一個安裝項目。 為此,必須首先創(chuàng)建一個解決方案包含簡單的 Windows 服務(wù)項目,將項寫入它的應(yīng)用程序日志。 然后您將一個安裝程序項目添加到解決方案以安裝 Window 服務(wù)。 ***,您啟動該服務(wù)。 您可以通過使用開始菜單中的管理工具文件夾中的服務(wù)項啟動服務(wù)。

C#Windows服務(wù)程序之為Windows 服務(wù)創(chuàng)建安裝項目

此部分介紹了如何創(chuàng)建 Windows 服務(wù)項目,以及如何使用一個已編譯的安裝項目若要安裝 Windows 服務(wù)。

C#Windows服務(wù)程序之創(chuàng)建一個 Windows 服務(wù)項目

1、啟動Microsoft Visual Studio。

2、在 文件 菜單上, 指向 新建 ,然后單擊 Project 。

3、在 項目類型 ,下單擊 Visual C# 項目 ,然后在 模板 下單擊 Windows 服務(wù) 。

注意 在 Visual Studio 2005 或 Visual Studio 2008,展開 Visual C# 項目類型 下,單擊 Windows ,然后單擊 Windows 服務(wù) 在 模板 下。

4、類型 LogWriterService 名稱 文本框中,然后鍵入 C:\ 在 位置 文本框中中。 單擊 確定 。

5、在解決方案資源管理器, Service1.cs ,右鍵單擊,然后單擊 查看代碼 。

6、在 OnStart 事件處理程序中, 替換注釋以下代碼:

EventLog.WriteEntry("My simple service started.");

7、在解決方案資源管理器,雙擊 Service1.cs 。

8、在代碼編輯器窗口,用鼠標右鍵單擊 設(shè)計視圖 ,然后單擊 屬性

9、在屬性窗格中, 單擊 添加安裝程序 鏈接。

10、在為 ServiceInstaller 1 屬性窗格,更改 ServiceName 屬性,以 Service 1 。

11、在設(shè)計視圖中代碼編輯器窗口,單擊 ServiceProcessInstaller 1 。

12、在屬性窗格,將 帳戶 屬性更改為 LocalSystem (: LocalService 和 NetworkService 值都可僅在 Microsoft Windows XP 中獲得)。

使用一個已編譯的安裝程序項目來安裝 Windows 服務(wù)

在完成上一節(jié)來配置 Windows 服務(wù)項目中的步驟之后,請按照下列步驟添加部署項目打包服務(wù)應(yīng)用程序以便可以安裝服務(wù)應(yīng)用程序的操作:

1、將一個新的項目添加到您的 LogWriterService 項目中。 為此,請按照下列步驟操作:

a、在解決方案資源管理器,右鍵單擊 解決方案 LogWriterService (1 項目) ,指向 添加 ,然后單擊 新建項目 。

b、單擊 安裝和部署項目 在 項目類型 ,然后在 模板 下單擊 安裝程序項目 。

c、在 名稱 文本框中,鍵入 ServiceSetup 。

d、類型 C:\ 位置 文本中框,然后再單擊 確定 。

2、告訴在部署項目的內(nèi)容到程序包。 為此,請按照下列步驟操作:

a、在解決方案資源管理器,右鍵單擊 ServiceSetup ,指向 添加 ,然后單擊 Project Output (項目輸出

b、在 添加項目輸出組 對話框, 項目 框中的單擊 LogWriterService

c、單擊 Primary output (主要輸出) ,然后單擊 確定 。

3、為正確的安裝,添加僅主輸出。 要添加自定義操作,請按照下列步驟操作:

a、在解決方案資源管理器,右鍵單擊 ServiceSetup ,指向 視圖 ,然后單擊 自定義操作

b、用鼠標右鍵單擊 自定義操作 ,然后單擊 添加自定義操作 。

c、單擊 主輸出 LogWriterService (Active) ,然后單擊 確定 。

您會注意到 主輸出 出現(xiàn)在 安裝 、 提交 、 回滾 和 卸載 。

4、默認情況下生成配置中不包含安裝程序項目。 為構(gòu)建C#Windows服務(wù)程序解決方案,使用下列方法之一:

C#Windows服務(wù)程序方法 1

用鼠標右鍵單擊 LogWriterService ,然后單擊 生成 。

用鼠標右鍵單擊 ServiceSetup ,然后單擊 生成 。

C#Windows服務(wù)程序方法 2

在 生成 菜單上, 單擊 配置管理器 來構(gòu)建整個解決方案。

單擊以選中 生成 復(fù)選框為 ServiceSetup。

按 F 7 鍵來構(gòu)建整個解決方案。 生成解決方案時, 必須可用于該服務(wù)是完整的安裝包。

5、若要安裝新建的服務(wù), ServiceSetup ,右鍵單擊,然后單擊 安裝 。

6、在 ServiceSetup 對話框,單擊 下一步 三次。 您會注意到一個進度欄出現(xiàn)服務(wù)安裝期間。

7、安裝服務(wù)時, 單擊 關(guān)閉 。

  1. using System;  
  2. using System.Collections;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Diagnostics;  
  6. using System.ServiceProcess;  
  7.  
  8. namespace LogWriterService  
  9. {  
  10. public class Service1 : System.ServiceProcess.ServiceBase  
  11. {  
  12. /// ﹤summary﹥   
  13. /// Required designer variable.  
  14. /// ﹤/summary﹥  
  15. private System.ComponentModel.Container components = null;  
  16.  
  17. public Service1()  
  18. {  
  19. // The Windows.Forms Component Designer must have this call.  
  20. InitializeComponent();  
  21.  
  22. // TODO: Add any initialization after the InitComponent call  
  23. }  
  24.  
  25. // The main entry point for the process  
  26. static void Main()  
  27. {  
  28. System.ServiceProcess.ServiceBase[] ServicesToRun;  
  29.  
  30. // More than one user service may run in the same process. To add  
  31. // another service to this process, change the following line to  
  32. // create a second service object. For example,  
  33. //  
  34. //   ServicesToRun = New System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};  
  35. //  
  36. ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service1() };  
  37.  
  38. System.ServiceProcess.ServiceBase.Run(ServicesToRun);  
  39. }  
  40.  
  41. /// ﹤summary﹥   
  42. /// Required method for Designer support - do not modify   
  43. /// the contents of this method with the code editor.  
  44. /// ﹤/summary﹥  
  45. private void InitializeComponent()  
  46. {  
  47. components = new System.ComponentModel.Container();  
  48. this.ServiceName = "Service1";  
  49. }  
  50.  
  51. /// ﹤summary﹥  
  52. /// Clean up any resources that are being used.  
  53. /// ﹤/summary﹥  
  54. protected override void Dispose( bool disposing )  
  55. {  
  56. if( disposing )  
  57. {  
  58. if (components != null)   
  59. {  
  60. components.Dispose();  
  61. }  
  62. }  
  63. base.Dispose( disposing );  
  64. }  
  65.  
  66. /// ﹤summary﹥  
  67. /// Set things in motion so your service can do its work.  
  68. /// ﹤/summary﹥  
  69. protected override void OnStart(string[] args)  
  70. {  
  71. EventLog.WriteEntry("My simple service started.");  
  72. }  
  73.  
  74. /// ﹤summary﹥  
  75. /// Stop this service.  
  76. /// ﹤/summary﹥  
  77. protected override void OnStop()  
  78. {  
  79. // TODO: Add code here to perform any tear-down necessary to stop your service.  
  80. }  
  81. }  
  82. }  

C#Windows服務(wù)程序驗證它正常工作

1、在控制面板,雙擊 管理工具 ,然后雙擊 服務(wù)

2、用鼠標右鍵單擊 Service 1 ,然后單擊 開始

3、使用以下方法之一來驗證事件日志中記錄一個事件:

C#Windows服務(wù)程序驗證方法 1

a、在控制面板中, 雙擊 管理工具 ,然后雙擊 事件查看器 。

b、在左窗格中, 單擊 應(yīng)用程序日志 ,然后查找從右窗格中您的服務(wù)在事件日志中。

C#Windows服務(wù)程序驗證方法 2

a、在 Server Explorer (服務(wù)器資源管理器,) 中展開 服務(wù)器 、 ComputerName、 事件日志 、 展開 應(yīng)用程序 ,然后展開 Service 1 。 請記住 Service 1 是類,非服務(wù)的名稱本身。 因此, Service 1 用作應(yīng)用程序的名稱。 (它是超出了本文說明了如何自定義名稱的范圍。

b、日志條目上移動光標。 從頂部第二個條目應(yīng)閱讀"我的簡單服務(wù)開始"。

C#Windows服務(wù)程序之安裝項目的基本內(nèi)容就向你介紹到這里,希望對你了解和學習C#Windows服務(wù)程序有所幫助。

【編輯推薦】

  1. C#啟動windows服務(wù)的方法淺析
  2. C#windows服務(wù)狀態(tài)改變操作淺析
  3. C#Windows服務(wù)程序開發(fā)實例介紹
  4. C#啟動Windows服務(wù)及關(guān)閉實例實現(xiàn)
  5. C#啟動Windows服務(wù)的窗體程序淺析
責任編輯:仲衡 來源: 百度空間
相關(guān)推薦

2009-08-14 13:41:13

C#Windows服務(wù)

2009-08-14 15:47:18

C#Windows服務(wù)

2009-08-14 15:19:38

Windows服務(wù)程序Windows服務(wù)

2009-08-14 15:06:08

Windows服務(wù)程序

2009-08-14 14:25:09

Windows服務(wù)程序

2009-08-14 14:45:03

C#Windows服務(wù)

2009-08-14 16:24:00

Windows服務(wù)程序

2009-08-14 14:17:16

C#Windows服務(wù)

2009-08-14 11:15:19

文件監(jiān)視C#Windows服務(wù)

2009-08-14 15:54:50

Windows服務(wù)程序C#Windows服務(wù)

2009-08-14 10:50:09

Windows服務(wù)介紹

2009-08-14 17:27:30

C#Windows應(yīng)用

2009-08-14 17:43:20

C#Windows應(yīng)用

2009-08-14 14:53:55

WINDOWS服務(wù)交互

2009-08-14 17:55:52

C#Windows應(yīng)用

2009-08-14 16:13:25

C#windows服務(wù)

2009-08-14 17:51:32

C#Windows應(yīng)用

2009-08-14 18:04:59

C#Windows應(yīng)用

2009-08-14 17:36:20

C#Windows應(yīng)用

2009-08-14 10:42:16

Timer控件的使用C#windows服務(wù)
點贊
收藏

51CTO技術(shù)棧公眾號