关于编程Windows服务:如何停止我的Windows服务?
这是一个非常简化的示例代码(C#):
// Here is my service class (MyTestService.cs).
public class MyTestService:ServiceBase{
// Constructor.
public MyTestService(){
this.ServiceName = "My Test Service";
return;
}
};
// My application class (ApplicationClass.cs).
public static class ApplicationClass{
// Here is main Main() method.
public static void Main(){
// 1. Creating a service instance
// and running it using ServiceBase.
MyTestService service = new MyTestService();
ServiceBase.Run(service);
// 2. Performing a test shutdown of a service.
service.Stop();
Environment.Exit(0);
return;
};
};
Run Code Online (Sandbox Code Playgroud)
所以:我刚刚创建了"我的测试服务"启动它并停止了.但是当我查看我的Services.msc时 - "我的测试服务"继续运行并且仅在我点击"停止"链接时停止.为什么?- 为什么service.Stop() …