使用 InstallUtil -u 移除服務:
installutil -u F:\Programs\C#\TestService\TestService\bin\Debug\testservice.exe

public partial class MyFirstService : ServiceBase
{
public MyFirstService() { InitializeComponent(); }
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("Service start");
// TODO: 啟動背景執行緒執行工作
}
protected override void OnStop()
{
eventLog1.WriteEntry("Service stop");
// TODO: 清理資源、停止執行緒
}
}
實務上 OnStart 應啟動獨立執行緒處理長時間工作,避免封鎖服務控制管理器 (SCM)。