The service is not responding to the control function (error 2186)
For me it just meant that an exception was being thrown. (Platform conflict in Configuration Manager, resulting in "bad image format".) Try running the .exe from the command line and see if you get an error.
Usually this happens if you're trying to do too much work in the OnStart
call. For example, if you start an endless loop in the same thread, you'll get this error message.
Generally the service should create a new thread in the OnStart
call, and then cleanly terminate it in the OnStop
call.
Of course that doesn't help if you're using code which was previously working. Have you tried rebooting it since the failure? I seem to remember that if you've already got a service which is borked, it can sometimes be tricky to get back to a working state without rebooting it. You may want to look in your process list and see whether you've got a copy still running, and kill it if so.
In general every service must do following two simple things
- if the service manager send him a control code like
SERVICE_CONTROL_START
,SERVICE_CONTROL_STOP
and so on if should return in a short interval. UsingSetServiceStatus
function service can prolong this interval for example with callingSetServiceStatus
with incrementeddwCheckPoint
value. (In .NET use can use ServiceBase.RequestAdditionalTime instead) - every service must answer to
SERVICE_CONTROL_INTERROGATE
control code just with return. This control code are used from the service manager to detect whether the service still living.
If your program don't follow one of the rules you receive the error "The service is not responding to the control function."
If you write a program in .NET you don't need to do directly the two things which I described before. The ServiceBase
class do there for you. Nevertheless you can easy break this rules if create a thread running with priority higher as normal or if you do some too long work inside an OnXXX handle (OnStop
, OnStart
, OnPowerEvent
etc) without calling of ServiceBase.RequestAdditionalTime. Some other tricks with additional threads can also make problems.