Can a Windows service stop itself?

亡梦爱人 提交于 2019-11-30 14:39:03

问题


I have a Windows service whose startup type is automatic, but I want to do some checks when the service starts, and have the service stop automatically if these checks fail.

How can I do this? My service is written in C#.


回答1:


You can call the Stop method on your ServiceBase class. See msdn for more details.




回答2:


You can use ServiceController and call .stop.

ServiceController sc= new ServiceController(service);
sc.Stop();


来源:https://stackoverflow.com/questions/11770206/can-a-windows-service-stop-itself

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!