启动windows服务的超时时间是多少?

发布于 2024-07-27 15:54:02 字数 348 浏览 2 评论 0原文

我已经部署了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

云仙小弟 2024-08-03 15:54:02

在您的服务类中,在 OnStart/OnStop 方法中使用 ServiceBase.RequestAdditionalTime()

// request an additional 4 seconds to complete the operation
RequestAdditionalTime(4000);  

In your service class, use ServiceBase.RequestAdditionalTime() in your OnStart/OnStop method:

// request an additional 4 seconds to complete the operation
RequestAdditionalTime(4000);  
梦里南柯 2024-08-03 15:54:02

创建服务的正常方法是让启动代码创建一个新线程,并在该线程中运行您的服务。

服务启动应该几乎是瞬时的——只不过是生成一个新线程,其中包含您的“真正”工作。

如果您花费的时间超过三秒,则表明您正在主线程中完成真正的工作,而不是为您的服务创建单独的工作。

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.

秋心╮凉 2024-08-03 15:54:02

根据具体问题,确切的超时时间有所不同,但都小于 30 秒。 您可以通过注册表项控制服务的默认启动超时,您可以在此处查看如何执行此操作< /a>.

然而,我同意许多其他人的观点,即我会考虑两种可能的选择。

  1. 尽快启动你的服务,生成一个线程,等等。
  2. 如果你不能选择选项一,你可以使用RequestAdditionalTime()。 请务必尽早拨打此电话。

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.

  1. Get your service started ASAP, spawn a thread, etc..
  2. If you cannot go with option one, you can use RequestAdditionalTime(). Just be sure to make this call early on.
雨落星ぅ辰 2024-08-03 15:54:02

另外,如果您在不同的物理环境中测试了该服务,问题似乎不是正常的启动时间,而是电脑的性能。 您可以增加特定 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文