Alex Rivera | Logout

ServiceController seems to be unable to stop a service

Asked 2011-06-09T12:15:57.420
35

I'm trying to stop a Windows service on a local machine (the service is Topshelf.Host, if that matters) with this code:

serviceController.Stop();
serviceController.WaitForStatus(ServiceControllerStatus.Stopped, timeout);

timeout is set to 1 hour, but service never actually gets stopped. Strange thing with it is that from within Services MMC snap-in I see it in "Stopping" state first, but after a while it reverts back to "Started". However, when I try to stop it manually, an error occurs:

Windows could not stop the Topshelf.Host service on Local Computer.
Error 1061: The service cannot accept control messages at this time.

Am I missing something here?

Edit
Report

2 Answers

2

I've seen this issue as well, specifically when a service is start pending and I send it a stop programmatically which succeeds but does nothing. Also sometimes I see stop commands to a running service fail with this same exception but then still actually stop the service. I don't think the API can be trusted to do what it says. This error message explanation is quite helpful...

http://technet.microsoft.com/en-us/library/cc962384.aspx

answered 2011-07-05T16:38:47.913
0

I just fought this problem while moving code from an old multi partition box to a newer single partition box. On service stop I was writing to D: and since it didn't exist anymore I got a 1061 error. Any long operation during the OnStop will cause this though unless you spin the call off to another thread with a callback delegate.

answered 2011-07-29T19:54:29.210

Your Answer