Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while stopping windows service

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      
}
like image 717
Asdfg Avatar asked May 04 '11 18:05

Asdfg


2 Answers

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

like image 103
Harun Avatar answered Oct 24 '22 15:10

Harun


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.

like image 27
Chris Shain Avatar answered Oct 24 '22 14:10

Chris Shain