本文介绍了强制窗口等待服务,当它被关闭,停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想不通关于Windows服务我已经写在C#中的一个问题。我所要做的就是等待一个子进程终止之前,我不得不杀了它,并停止该服务在指定的时间。我已经把我的超时时间,任何地方从5到15秒,我的服务等待的时间适量,然后杀死了孩子和停止时,我通过MMC服务窗口停止。但是,如果我关机的电脑我的服务被风吹走之前,它能够等待和停止正常。我已经阅读了Windows允许30秒关机服务超时它吹它拿走了。我的code正在执行超过30秒的时间要少得多,最多约20秒左右,这取决于我设置超时时间。

I'm having an issue that I can't figure out regarding a Windows Service I have written in C#. What I am trying to do is wait for a specified period for a child process to terminate before I am forced to kill it and stop the service. I have set my timeout for anywhere from 5 to 15 seconds and my service waits the appropriate amount of time and then kills the child and stops when I stop it via the mmc service window. However if I shutdown the computer my service gets blown away before it is able to wait and stop properly. I have read that Windows allows for a timeout of 30 seconds for a service to shutdown before it blows it away. My code is executing in much less time than 30 seconds, max is around 20 seconds or so, depending on what I set the timeout at.

我使用Win32 API中的SetServiceStatus()函数都试过,但它并没有改变的code的作用。我已验证函数调用成功。是否有任何其他的方式来强制Windows正确地等待我的服务关机?我测试它在Windows 7中的x86和Windows Vista SP1的86。

I have tried using the SetServiceStatus() function in the win32 Api but it has not changed the function of the code. I have verified that the function call is succeeding. Is there any other way to force Windows to wait for my service to shutdown properly? I am testing it in Windows 7 x86, and Windows Vista Sp1 x86.

推荐答案

Windows会的不可以让任何服务prevent关机,这是由设计。作为Gyuri说,你必须要考虑不同的设计为您的应用程序。

Windows will not let any service prevent shutdown, this is by-design. as Gyuri says, you have to consider a different design for your app.

这篇关于强制窗口等待服务,当它被关闭,停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 04:28