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
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.
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.
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.
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.
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.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With