Windows 服务不会停止
我有一个关于我已经实现的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有任何线程,请确保在停止例程中退出这些线程。有些线程可能仍然徘徊,这就是它不会停止的原因。
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.
一个可能的原因可能是由于一些剩余的线程(如“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 itsdwControlsAccepted
set to acceptshutdown or stop
(by settingSERVICE_ACCEPT_SHUTDOWN & SERVICE_ACCEPT_STOP
). and don't forget to update the service status (usingSetServiceStatus
function) once the service is up and running.