本文介绍了什么时候调用服务的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!

推荐答案



相反 - 当请求服务停止时,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.





我可能有误解了响应,但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()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 22:35