[英]1053 windows service did not respond in timely fashion
I have one Web app running in IIS and communicates to a Windows Service through WCF hosted in the same machine. 我有一个在IIS中运行的Web应用程序,并通过托管在同一台机器上的WCF与Windows服务进行通信。 Internally Windows Service executes various job and sometimes it is quite busy with processing User requests.
内部Windows服务执行各种作业,有时它非常忙于处理用户请求。 At 1st I had the issue with Start of Service because it some imes take much time to Start & eventually throws the Error ie Service Timeout.
在第一天,我遇到了服务开始的问题,因为它有些时间需要花费很多时间来启动并最终抛出错误即服务超时。 To fix this I moved the code to another Thread instead of the Main Thread.
为了解决这个问题,我将代码移到另一个Thread而不是Main Thread。 Everything works fine but now I observed that some times I am getting the error on Service Stop ie
一切正常,但现在我发现有时我收到服务停止的错误即
**1053 windows service did not respond in timely fashion**
My Service OnStop() code: 我的服务OnStop()代码:
protected override void OnStop()
{
// Stop the WCF service
if (myServiceHost != null)
{
myServiceHost.Close();
myServiceHost = null;
}
// Stop the scheduler
if (myScheduleManager != null)
{
myScheduleManager.Stop();
}
// Update the registry value
Logger.GetInstance().LogEvent(this.GetType().Name, LogLevel.INFO, "Updating registry...");
Settings.GetInstance().LastStopTime = DateTime.Now.ToString();
Logger.GetInstance().LogEvent(this.GetType().Name, LogLevel.INFO, "Service stopped.");
}
It generally happens when Service is too busy. 通常在服务太忙时发生。 But finally it stops after 30-40 mins of time.
但最终它在30-40分钟后停止。 I know this happens due to Time out issue in Windows Service coz the default time is very less & it treats it as Time out.
我知道这是由于Windows服务中的超时问题而发生的,因为默认时间非常短,并将其视为超时。
My question what is the best practice to avoid such bottle necks means shall I move my Stop related tasks under another Thread & do asynchronous call to release resources in that Thread. 我的问题是什么是避免这种瓶颈的最佳实践意味着我应该将我的Stop相关任务移动到另一个Thread并执行异步调用以释放该Thread中的资源。 But what will happen if during release resources, User will Start the Service?
但是如果在发布资源期间,用户将启动服务会发生什么?
Just guessing, but perhaps it will help to track down the problem: 只是猜测,但也许它将有助于追查问题:
You have this myScheduleManager.Stop()
which, (i guess) waits for processes to be finished. 你有这个
myScheduleManager.Stop()
,(我猜)等待进程完成。 This is nice, but Windows only gives you 30 Seconds to execute ServiceBase.OnStop()
. 这很好,但Windows只给你30秒执行
ServiceBase.OnStop()
。
If you are doing asynchronous processing here, you could perhaps implement the CancellationPattern by using the CancellationTokens from the .NET-Framework. 如果您在此处进行异步处理,则可以使用.NET-Framework中的CancellationTokens实现CancellationPattern。
The easy approach probably you can identify to build a boolean type IsRunning
in your myScheduleManager
and determine during the OnStop() 您可以通过简单的方法识别在
myScheduleManager
构建布尔类型IsRunning
并在OnStop()期间确定
if (myScheduleManager.IsRunning)
myScheduleManager.Stop();
however, you have different threads finishing the processes which could over 30 seconds but you also can do abort your processes by applying 但是,您有不同的线程完成可能超过30秒的过程,但您也可以通过应用中止您的过程
if (myScheduleManager.IsRunning && !_workerThread.Join(TimeSpan.FromSeconds(30))
_workerThread.Abort
myScheduleManager.Stop();
However, I didn't see the full code snippets so that's my guess to your scenario. 但是,我没有看到完整的代码片段,所以这是我对你的场景的猜测。
只是猜测但它可能有所帮助:确保将解决方案配置设置为Release而不是Debug。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.