首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> ASP.NET 基礎 >> 關於ASP.NET

MCAD 學習筆記:Windows 服務開發與安裝完整指南

     編輯:關於ASP.NET

Windows 服務特性

  • 背景執行,無使用者介面。
  • 適合非互動式任務 (排程、監聽、批次處理)。
  • 支援 Windows 2000/XP/NT 等。

核心命名空間

System.ServiceProcess

關鍵類別

  • ServiceBase:服務邏輯基類,覆寫 OnStart/OnStop/OnPause/OnContinue/OnShutdown/OnPowerEvent/OnCustomCommand。
  • ServiceInstaller:安裝服務專案輸出組件。
  • ServiceProcessInstaller:設定服務帳戶 (LocalSystem/NetworkService/LocalService/User)。

ServiceBase 重要屬性

  • ServiceName:服務唯一名稱。
  • AutoLog:自動記錄狀態變更至事件檢視器。
  • CanStop/CanPauseAndContinue/CanShutdown/CanHandlePowerEvent:啟用對應虛擬方法。

建立與安裝步驟

  1. 新增「Windows Service」專案。
  2. 設計介面右鍵「Add Installer」產生 ProjectInstaller (含 ServiceProcessInstaller + ServiceInstaller)。
  3. 設定 ServiceProcessInstaller.Account、ServiceInstaller.StartType (Automatic/Manual/Disabled)。
  4. 建置產生 .exe。
  5. 安裝:InstallUtil.exe MyService.exe。
  6. 解除安裝:InstallUtil.exe /u MyService.exe。

程式化控制

ServiceController 類別:Start()/Stop()/Pause()/Continue()、屬性 Status、ServiceName。

總結

Windows 服務以 ServiceBase 封裝邏輯,Installer 標準化部署,ServiceController 提供管理介面,是長期運行背景任務的標準解決方案。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved