Handling delays during stop/pause requests on Windows service

我与影子孤独终老i 提交于 2019-12-04 13:13:20

You can use the RequestAdditionalTime method to inform the SCM that you need more time to stop/pause your service.

I butted my head against the SCM giving up causing my service to freeze up like it was sunbathing in Antarctica in June.

The issue for me was that the service did some processing that potentially could take longer than the SCM is willing to wait for it to respond to a stop request.

I like my software to start/exit/pause and even die gracefully.

The solution I implemented was to use a config file. I put an ExecutionMode parameter in the file. At the start of every processing loop, it checks the config file - if ExecutionMode is Pause or Stop, then it executes code to change state and uses SMTP to send an email to the email ids listed in a ServiceChangeNotification paramete. Details included in the email are Machine name, Timestamp, Service Name, Old State, Old State Start Time, Current State, Current State Start Time, Log details.

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