小编rom*_*nko的帖子

如何以编程方式停止Windows服务

关于编程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() …

.net c# windows service

20
推荐指数
2
解决办法
4万
查看次数

标签 统计

.net ×1

c# ×1

service ×1

windows ×1