windows服务启动超时
有没有办法为每个服务设置不同的服务启动超时值? 我可以使用 ServicesPipeTimeout 注册表项更改它,但它是针对每台计算机的 (http://support.microsoft.com/ kb/824344)。
目前我唯一想到的就是在不同的线程中完成所有耗时的启动操作。
Is there a way to set a different value for service startup timeout per service?
I can change it using the ServicesPipeTimeout registry key, but it's per machine (http://support.microsoft.com/kb/824344).
At the moment the only thing I thought about was to do all the time-consuming startup actions in a different thread.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我同意罗慕洛的观点,即尽快完成为您提供服务。 但是,如果您需要时间并且使用的是 .NET Framework 2.0 或更高版本,则可以考虑 ServiceBase.RequestAdditionalTime() 方法。
http://msdn.microsoft.com/en-我们/library/system.serviceprocess.servicebase.requestadditionaltime.aspx
I agree with Romulo on finishing to start your service as soon as possible. However, if you need the time and you are using .NET Framework 2.0 or later, you might consider ServiceBase.RequestAdditionalTime() method.
http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicebase.requestadditionaltime.aspx
尽快完成服务启动是一个很好的做法。 因此,在启动状态期间,仅执行确认其成功启动所需的操作; 其余的稍后再做。 如果启动仍然是一个漫长的过程,请使用SetServiceStatus< /a> 定期通知服务控制管理器您尚未完成,因此它不会使您的服务超时。
It's good practice to finish starting your service as fast as possible. So, during the start state, do only what you absolutely need to acknowledge it started successfully; and do the rest later. If the start is still a lengthy process, use SetServiceStatus periodically to inform the Service Control Manager that you have not yet finished, so it does not time-out your service.
只需在另一个线程中执行耗时的操作
Simply do timeintensive stuff in another thread
我还必须处理一项服务,该服务可能需要几秒钟/分钟才能有一个良好的开始。 当服务启动时,它会尝试连接到 SQL Server。 然而,当整个服务器重新启动时,我的服务在 SQL Server 之前启动。 (我知道服务依赖性,但由于特定原因它不适用于我的情况......)。 我尝试循环尝试连接 SQL Server 10 次,但由于超时,Windows 在第二次尝试之前终止了我的服务。
我的解决方案:我在服务的“onStart()”中添加了一个计时器。 然后,该服务的“onTick()”方法尝试连接到 SQL Server 10 次(其中等待了 30 次)。 启动时不再超时。
所以基本上,
开始了。
连接到 SQL Server。
请注意解决问题的更优雅的方法,但也许我的解决方案的某些部分可以帮助任何比我处于相同情况的人,
I also had to deal with a service which may takes a few seconds/minutes to have a good Start. When the service starts, it tries to connect to a SQL Server. However, when the whole server was restarted , my service was starting BEFORE SQL Server. (I know about the Service dependency but it dont apply to my situation for a particular reason....). I tried to do a loop trying 10 times to connect to SQL Server, but Windows was killing my service before the 2nd try, because of the Timeout.
My solution : I added a Timer in the "onStart()" of my service. Then, the "onTick()" method of the service was trying 10 times to connect to the SQL Server (with a waiting of 30 in it). No more Timeout at startup.
So basically,
started.
connect to the SQL Server.
Note the more elegant way to resolve the problem but maybe some part of my solution may help anybody in the same situation than me,