自动调用Windows服务的onstop()方法 [英] call onstop() method of windows service automatically
本文介绍了自动调用Windows服务的onstop()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我已经使用线程和计时器在Windows服务中每n分钟执行一些工作.在OnStart()方法中一切正常,但问题是系统关闭或重新启动时OnStop()方法未调用.我已经搜索了很多但没有发现...
我的错误是什么?
Hi all,
I have used Thread and timer to do some works every n minutes in a windows service. every thing goes fine in OnStart() method but the problem is the OnStop() method does not call when the system is shutting down or restart.I have searched a lot but nothing found...
what is my mistake???
推荐答案
请通过此链接
http://stackoverflow.com/questions/5202119/detect-shutdown-in-window-service
http://stackoverflow.com/questions/7441061/can- a-windows-service-take-hours可以正常关闭
Please go through this link
http://stackoverflow.com/questions/5202119/detect-shutdown-in-window-service
http://stackoverflow.com/questions/7441061/can-a-windows-service-take-hours-to-shutdown-gracefully
这是使用类Microsoft.Win32.SystemEvents
完成的.它具有一些可以在服务中处理的事件.特别是,请参见事件Microsoft.Win32.SystemEvents
.请注意各个MSDN页面上的代码示例:
http://msdn.microsoft.com/en-us/library/microsoft.win32. systemevents.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/microsoft. win32.systemevents.sessionending.aspx [ ^ ].
—SA
This is done using the classMicrosoft.Win32.SystemEvents
. It has some events you can handle in your service. In particular, please see the eventMicrosoft.Win32.SystemEvents
. Pay attention for the code sample on respective MSDN pages:
http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.aspx[^],
http://msdn.microsoft.com/en-us/library/microsoft.win32.systemevents.sessionending.aspx[^].
—SA
这篇关于自动调用Windows服务的onstop()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文