启动windows服务的超时时间是多少?
我已经部署了 Windows 服务(使用独立安装程序类和 SC.EXE),但是当我尝试启动它时出现错误:
---------------------------
Services
---------------------------
Could not start the MyName service on Local Computer.
Error 1053: The service did not respond to the start or control request in a timely fashion.
超时是多少? 感觉好像3秒左右。 如果我的服务时间更长,我需要做什么?
I have deployed my windows service (using independently installer class and SC.EXE), but I get an error when I try to start it:
---------------------------
Services
---------------------------
Could not start the MyName service on Local Computer.
Error 1053: The service did not respond to the start or control request in a timely fashion.
What is the timeout? It felt like around 3 secs. What do I need to do if my service takes longer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在您的服务类中,在 OnStart/OnStop 方法中使用
ServiceBase.RequestAdditionalTime()
:In your service class, use
ServiceBase.RequestAdditionalTime()
in your OnStart/OnStop method:创建服务的正常方法是让启动代码创建一个新线程,并在该线程中运行您的服务。
服务启动应该几乎是瞬时的——只不过是生成一个新线程,其中包含您的“真正”工作。
如果您花费的时间超过三秒,则表明您正在主线程中完成真正的工作,而不是为您的服务创建单独的工作。
The normal way of creating a service is to have the startup code create a new thread, and run your service in that thread.
The service startup should be nearly instantaneous - nothing more than spawning a new thread with your "real" work in it.
If you're taking more than three seconds, that's a sign that you're doing the real work in your main thread, and not creating a separate one for your service.
根据具体问题,确切的超时时间有所不同,但都小于 30 秒。 您可以通过注册表项控制服务的默认启动超时,您可以在此处查看如何执行此操作< /a>.
然而,我同意许多其他人的观点,即我会考虑两种可能的选择。
In regards to the specific question, the exact timeout varies, but is less than 30 seconds. You can control the default startup timeout for a service via a registry key, you can see how to do this here.
However, I will agree with many others that I would look at two possible options.
另外,如果您在不同的物理环境中测试了该服务,问题似乎不是正常的启动时间,而是电脑的性能。 您可以增加特定 PC 的注册表项的超时时间。
请参见:
http://support.microsoft.com/kb/839803
问候
Also if you had tested the service in different Physical environments, and it seems that the issue is not the normal startup time but the performance of the PCs. You can increase the timeout on the registry key for the specific PC.
Please see:
http://support.microsoft.com/kb/839803
Regards