Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to increase window service timeout

Tags:

c#

window

service

i am facing problem during starting my window service... as there is a big load on OnStart() event of my service, it scrap data, saved it to database and send email. So my service need to increase start time because the defualt timeout is 30second... i have released that my service will need additional time to start when i face the following exception..

"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."

Plz help me... Thanx in advance

like image 837
user2499974 Avatar asked Aug 22 '13 12:08

user2499974


People also ask

How do I increase Windows service timeout?

In the New Value #1 box, type ServicesPipeTimeout, and then press ENTER. 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.

How do I keep a service running in Windows?

Enable service Open Start. Search for Command Prompt, right-click the top result, and select the Run as administrator option. Type the following command to enable a service and press Enter: sc config "SERVICE-NAME" start=auto In the command, replace "SERVICE-NAME" for the name of the service that you want to enable.

What is service timeout?

Timeouts happen if a service takes more than 30 seconds to respond to a call. If a timeout occurs, you'll see the 500 error status code with details about the timeout in the response. Timeouts are typically caused by one of two things: The call involves too much data. There is a network/service issue.

How do I check Windows timeout?

Press Win + I to open the system settings. Select the Personalization option from the menu items. Click the Lock screen option on the left-hand side pane. Scroll down on the right-hand side and click the Screen timeout settings option.


2 Answers

i have realised that my service will need additional time to start when i face the following exception

doing long runnings tasks on constructor/start isn't good. you should start your long running task on a sperate thread.

Service startup should be instant and should not hang up.

However if you still want, you can do this

ServiceBase.RequestAdditionalTime(4000); // add 4 seconds

From MSDN

The RequestAdditionalTime method is intended to be called by the overridden OnContinue, OnPause, OnStart, or OnStop methods to request additional time for a pending operation, to prevent the Service Control Manager (SCM) from marking the service as not responding. If the pending operation is not a continue, pause, start, or stop, an InvalidOperationException is thrown.

like image 180
Ehsan Avatar answered Sep 28 '22 03:09

Ehsan


You better do your long operations in a Thread.

protected override void OnStart(string[] args)
{
  Thread thWorker = new Thread(new ThreadStart(
    delegate
    {
       // Do your long operations here
    }
  ));
  thWorker.Start();
}
like image 42
Farzan Avatar answered Sep 28 '22 03:09

Farzan