什么时候调用服务的OnShutDown()? [英] When does the service's OnShutDown() gets called ?

查看:85
本文介绍了什么时候调用服务的OnShutDown()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我想提交chages /想要在服务'OnShutuDown()上做一些活动。但我发现它已经被调用了。 。当我关闭系统或关闭系统时......两种情况都没有找到OnShutDown。

我的应用程序运行在Vista \ Winin server 2008上。有人告诉我这个OnShutDown()什么时候被调用..?


谢谢!

Hi ,

I want to commit the chages/ want to do some activity on service''s OnShutuDown().But i found that It neven get''s called ..when i shut down the system or when i power it off..in Both the cases call to OnShutDown not found.
I have my application running on Vista\Win server 2008 . CAn anybody tell me when does this OnShutDown() gets called.. ?

Thanks!

推荐答案


我想提交chages /想要在服务'OnShutuDown()上做一些活动。但是我发现当我关闭系统时或者当我关闭系统时我关掉电源..
I want to commit the chages/ want to do some activity on service''s OnShutuDown().But i found that It neven get''s called ..when i shut down the system or when i power it off..



相反 - 当请求服务停止时,OnShutDown()(当拼写正确时)被调用。如果它没有被调用,那么有些东西会阻止你的服务及时关闭。如果没有看到任何代码,我就无法开始猜测是什么。


我能想到的唯一一件事就是当你把系统关闭时与告诉服务停止在服务小程序中的情况不同,如果服务在指定的时间范围内没有停止 - 我认为默认值是1分钟...除非您安装了Exchange Server并且它已更改默认为10分钟(600000毫秒)。一旦发生超时,服务进程就会以不受控制的方式终止,通常它们的关闭过程没有成功完成,并且在某些情况下,关闭进程在进程被杀之前甚至都没有启动。


可悲的是,我不确定是否有办法解决这个问题......可能会延长超时时间,让您的服务有更多时间关闭。它需要一个mod到注册表,所以小心...


这里是注册表项:


HKEY_LOCAL_MACHINE \ SYSTEM \ \\ CurrentControlSet \Contro l \WaitToKillServiceTimeout


只需增加值(记住,它是以毫秒为单位,所以将其设置为60认为你将它设置为一分钟不会帮助这种情况)。当然,如果重新启动Windows需要更长的时间,请不要感到震惊。

On the contrary - OnShutDown() (when spelled correctly) gets called when the services is requested to stop. If it''s not being called then something is stopping your service from closing down in a timely manner. I couldn''t begin to hazard a guess at what that is without seeing any code.

The only thing I can think of is when you shut the system down it''s slightly different than when you tell the service to stop in the services applet, in that if the service doesn''t stop within the specified time frame - I think the default is 1 minute...unless you have Exchange Server installed and it is changed by default to 10 minutes (600000 milliseconds). Once this timeout occurs the service processes are terminated in an uncontrolled fashion, frequently their shutdown process isn''t complete successfully, and in some cases the shutdown process isn''t even started before the process is killed.

Sadly, I''m not sure if there''s a way around this... maybe extend the timeout period to give your service more time to close. It requires a mod to the registry, so careful...

Here''s the registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contro l\WaitToKillServiceTimeout

Just increase the value (remember, it''s in milliseconds, so setting it to 60 thinking you''re setting it to a minute won''t help the situation). Of course, don''t be shocked when it takes Windows longer to go down for a reboot.


感谢您的更新..


你的意思是说,对于每个服务,在注册表中的 WaitToKillServiceTimeout 值下有时间段定义,这在很长一段时间后停止服务..右..?


哦......谢谢..


但是我有点疯狂......正如你猜测的那样......可能会有一些东西阻止我的服务及时停止..如果是这种情况,如果WaitToKillServiceTimeout服务为600000,每10分钟后服务器的OnStutdown()应该被调用。日志应该打印..正如我在我的测试应用程序中所做的那样..如果我没有弄错你的点...如果我错了请纠正我。


如果有什么东西正在及时停止我的服务..可能是什么..你可以帮助我..你能给我任何建议..


根据代码的关注..

我创建了简单的Windows服务..覆盖OnStop(),OnShutDown(),OncustomeCommand()有趣..其余的是常见的...构造函数..等等


请告诉我你对此的反馈..


再次谢谢..
Thanks for the update ..

You mean to say for every service there is the timeperiod defind under WaitToKillServiceTimeout value in the registry which stops the service after this much period of time .. Right ..?

Ohh.. Thanks..

But I am a bit crazy about .. As you guessed .. that there might be something which is resisting my service from stoping in timely manner..If this is the case , what if there is the service with WaitToKillServiceTimeout as 600000 , after every 10 minutes the servic''s OnStutdown() should get called..i.e. The Logs should get printed .. as i did in my test application ..If I have not mistaken you point..Please correct me if I am wrong.

If there is something which is stoping my service in the timely manner.. what could be it.. Can you please help me.. can you give me any suggestions ..

As per as the code is concern..
I created the simple windows service .. overrided OnStop(), OnShutDown(),OncustomeCommand() fun.. Rest are the common.. constructors.. etc.

Please let me know your feedback over this..

Again thank you..



相反 - OnShutDown()(当拼写正确时)在请求服务停止时被调用....
On the contrary - OnShutDown() (when spelled correctly) gets called when the services is requested to stop....



我可能有误解了响应,但OnshutDown在操作系统关闭时执行,而不是在服务停止时执行。

I may have misunderstood the response but OnshutDown gets executed when the operating system is shutdown rather than when the service is stopped.


这篇关于什么时候调用服务的OnShutDown()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆