日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網營銷解決方案
C#Windows服務程序之安裝項目

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

10年積累的網站設計制作、成都網站建設經驗,可以快速應對客戶對網站的新想法和需求。提供各種問題對應的解決方案。讓選擇我們的客戶得到更好、更有力的網絡服務。我雖然不認識你,你也不認識我。但先做網站設計后付款的網站建設流程,更有遼陽免費網站建設讓你可以放心的選擇與我們合作。

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

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

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

1、啟動Microsoft Visual Studio。

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

C#Windows服務程序方法 1

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

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

C#Windows服務程序方法 2

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

單擊以選中 生成 復選框為 ServiceSetup。

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

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

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

7、安裝服務時, 單擊 關閉 。

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

C#Windows服務程序驗證它正常工作

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

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

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

C#Windows服務程序驗證方法 1

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

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

C#Windows服務程序驗證方法 2

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

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

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


本文題目:C#Windows服務程序之安裝項目
分享地址:http://www.dlmjj.cn/article/coohccj.html