窗口服务不要在计算机关闭时不停止 [英] window service do no not stop on computer shutdown
本文介绍了窗口服务不要在计算机关闭时不停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在c#中创建了一个窗口服务,它可以完美运行
但是问题是计算机关闭时我的服务没有停止
由于这些,在下次启动时,我的服务显示运行状态,但是它不执行其中的代码...
I have created a window service in c# it run perfectly
but the issue is when the computer shut downs my service doesn''t stop
because of these on the next startup my service show running status but it does not executes the code in it...
any suggestion or a rough idea would be appreciated
推荐答案
ServiceBase
具有OnStop()
,您应该重写并处理服务内部代码的干净关闭.
ServiceBase
has anOnStop()
which you should override and handle the clean shutdown of your service internal code.
您可以使用以下类来实现所需的目标:Microsoft.Win32.SystemEvents
:
https://msdn.microsoft.com/zh-我们/library/microsoft.win32.systemevents%28v=vs.110%29.aspx [
You can achieve what you want using the class:Microsoft.Win32.SystemEvents
:
https://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents%28v=vs.110%29.aspx[^].
—SA
这篇关于窗口服务不要在计算机关闭时不停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文