Windows 服务不会停止

发布于 2024-10-10 03:15:21 字数 193 浏览 0 评论 0原文

我有一个关于我已经实现的 Windows 服务的问题。该服务执行其必须执行的操作并记录各种信息,但是当我尝试停止它时,它似乎并没有停止并继续记录。

我对服务不太熟悉,所以如果有人知道为什么会发生这种情况,请告诉我。

编辑:我已经在两台服务器上测试了该服务,奇怪的是,在一台服务器上它正常停止,但在另一台服务器上却没有。这就是我不明白的地方。

I have a problem concerning a windows service that I have implemented. The service does what it has to and logs various information but when I try to stop it, it doesn't seem to stop and keeps logging.

I am not very familiar with services, so if anyone knows why this is happening please tell me.

Edit: I have tested the service on two servers and the weird thing is that on one server it stops normally, but on the other it doesn't. That is what I don't understand.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

浮生未歇 2024-10-17 03:15:21

如果您有任何线程,请确保在停止例程中退出这些线程。有些线程可能仍然徘徊,这就是它不会停止的原因。

IN case you have any threads ensure that you exit those threads in your stop routine. Some threads may still be lingering which is why it does not stop.

轻许诺言 2024-10-17 03:15:21

一个可能的原因可能是由于一些剩余的线程(如“ckv”提到的)。

您是否使用 RegisterServiceCtrlHandler 函数设置了正确的处理程序?
另请确保您使用的 SERVICE_STATUS 结构的 dwControlsAccepted 设置为接受关闭或停止(通过设置 SERVICE_ACCEPT_SHUTDOWN 和 SERVICE_ACCEPT_STOP )。并且不要忘记在服务启动并运行后更新服务状态(使用 SetServiceStatus 函数)。

One possible reason could be because of some remaining thread (as mentioned by 'ckv').

Have you set proper handler using RegisterServiceCtrlHandler function?
Also make sure that the SERVICE_STATUS structure that you use has its dwControlsAccepted set to accept shutdown or stop (by setting SERVICE_ACCEPT_SHUTDOWN & SERVICE_ACCEPT_STOP). and don't forget to update the service status (using SetServiceStatus function) once the service is up and running.

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