简体   繁体   中英

What is the timeout for starting a windows service?

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?

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

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

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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