通过计时器线程上的多线程处理优雅地停止 Windows 服务?

发布于 2024-08-30 05:38:54 字数 74 浏览 3 评论 0原文

如何通过计时器线程上的多线程处理优雅地停止 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉月流沐 2024-09-06 05:38:54

您必须在 OnStop() 方法中处理服务中线程的取消。
尝试使用 ManualResetEventAutoResetEvent
您可能还必须停止计时器。

You have to handle cancellation of the threads in your service in the OnStop() method.
Try some logic with ManualResetEvent or AutoResetEvent
You probably also have to stop your timer.

旧人 2024-09-06 05:38:54

您可能需要使用某种标志来指示线程是否应该停止。 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文