I am working on Windows Service. It works fine. When i am trying to stop the service from services.msc
, it throws the following error:
Windows could not stop the xxx service on Local Computer. The service did not return an error. This could be an internal Windows error or an internal service error. If the problem persists, contact your system administrator.
If I try to stop it again, it takes lots of time and then throws the error as below:
Windows could not stop the xxx service on Local Computer. Error 1061: The service cannot accept control messages at this time.
At this point, the service has stopped. But if I try to reinstall the service, it throws another error:
Windows could not stop the xxx service on Local Computer.
Error 1001: The specified service is marked for deletion.
After closing services.msc
, it lets me reinstall the service and again things start working fine.
In OnStop()
, I am doing some lengthy operations and it takes time to complete.
Any idea how I can make the whole thing go smoothly?
--Edit--
This is what my OnStop
method looks like:
protected override void OnStop()
{
base.OnStop();
//Some lengthy operation
}
The windows service have a default timeout in onstart and onstop events. Normally if you are doing time consuming operations in any of these events start a new thread and let the operation to perform in background.
Usually the OnStart as well as OnStop events within the windows service are used to initiate a process and the time consuming process will carryout it's execution within a child thread.
Hope this will solve your issue..
There is a registry entry that controls how much time windows gives services to shut down before giving up: http://support.microsoft.com/kb/146092
Trivially, increasing this time would fix the issue, assuming that your service is actually shutting down after that long operation.
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