Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 216
Grzenio Avatar asked Jul 21 '09 16:07

Grzenio


People also ask

What is service timeout?

The timeout property specifies the maximum time (in seconds) to wait for a response to be returned. The value minus one (-1) is the default value. The -1 value causes the property to be ignored, and the underlying web service engine's default value of 300 seconds will be used for the request timeout.

How do I increase Windows service timeout?

Right-click ServicesPipeTimeout, and then click Modify. Click Decimal, type the number of milliseconds that you want to wait until the service times out, and then click OK. For example, to wait 60 seconds before the service times out, type 60000. Quit Registry Editor, and then restart the computer.

What does delayed start mean for a Windows service?

In order to speed up the Windows boot process, Microsoft introduced Automatic (Delayed Start) Windows Services. The idea behind this was to delay the start of non-essential services in order to minimise the overall boot time of the operating system.


3 Answers

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

// request an additional 4 seconds to complete the operation
RequestAdditionalTime(4000);  
like image 99
Ben M Avatar answered Oct 22 '22 12:10

Ben M


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.

like image 23
Reed Copsey Avatar answered Oct 22 '22 12:10

Reed Copsey


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.
like image 28
Mitchel Sellers Avatar answered Oct 22 '22 12:10

Mitchel Sellers