简体   繁体   English

如何为长时间运行的作业停止Windows服务?

[英]How to Stop a Windows Service for long running Jobs?

Currently I am using Windows Service to keep on running some jobs in the background. 目前,我正在使用Windows Service在后台继续运行某些作业。 These jobs are scheduled via Quartz.Net. 这些作业是通过Quartz.Net计划的。 Generally these are long running jobs, spans from 5 min to 15 min. 通常,这些是长期运行的工作,范围从5分钟到15分钟。 If a job is currently running and if User will try to Shutdown the Windows Service then it throws Exception: Windows service did not respond in a timely fashion. 如果作业当前正在运行,并且用户将尝试关闭Windows服务,则它将引发异常: Windows服务未及时响应。

Actually OnShutdown() method of WindowsService, I am trying to Shutdown the Quartz.Net also. 实际上是WindowsService的OnShutdown()方法,我也在尝试关闭Quartz.Net。 I am calling scheduler.Shutdown(true) to stop the scheduler & wait for running jobs. 我正在调用scheduler.Shutdown(true)来停止调度程序并等待正在运行的作业。 If I will make this False then Windows Service Stops normally but it will put the running Job in Unstable state. 如果我将其设置为False,则Windows Service会正常停止,但是它将运行的Job置于不稳定状态。 Please help me on this. 请帮我。

You get this error because your service did not complete the Stop in the agreed-upon time. 您收到此错误消息是因为您的服务未在约定的时间内完成停止。 So, the SCM assumes it's hung in some way and aborts it. 因此,SCM假定它以某种方式挂起并中止。

To tell the SCM you need more time to complete the operation, call ServiceBase.RequestAdditionalTime() in your OnStop handler. 要告诉SCM您需要更多时间来完成操作,请在OnStop处理程序中调用ServiceBase.RequestAdditionalTime() For more information see http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicebase.requestadditionaltime.aspx 有关更多信息,请参见http://msdn.microsoft.com/zh-cn/library/system.serviceprocess.servicebase.requestadditionaltime.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM