通过计时器线程上的多线程处理优雅地停止 Windows 服务?
如何通过计时器线程上的多线程处理优雅地停止 Windows 服务?是否可以在 OnStop 方法中添加一些无限循环逻辑来推迟服务关闭。
How to gracefully stop a windows service with multi-threaded processing on a timer thread? Is it possible to add some infinite loop logic in the OnStop method to postpone the service shutting down.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须在
OnStop()
方法中处理服务中线程的取消。尝试使用
ManualResetEvent 或 AutoResetEvent
您可能还必须停止计时器。
You have to handle cancellation of the threads in your service in the
OnStop()
method.Try some logic with
ManualResetEvent
orAutoResetEvent
You probably also have to stop your timer.
您可能需要使用某种标志来指示线程是否应该停止。 SO 上已经有一个类似的问题 - 这里
You will probably need to use some sort of flag to indicate whether a Thread should stop or not. There is already a similar question on SO - here