C++ – The service did not respond to the start or control request in a timely fashion

cservicewinapi

I have created a service in win32,c++ . I am able to create the service , but when I try to start it, it gives following error.

[SC] StartService FAILED 1053:
The service did not respond to the start or control request in a timely fashion.

What is the best way to get to the root cause, since this error message is not conveying anything meaningful

Best Answer

Debugging services is hard. These days I prefer to write a class library that does all the work, a service that just calls one method of the class library, and a test harness (usually a console app) that calls the same method. That way I can run the test harness in the debugger and get most of the errors out of the way.

The two messages you tend to get when your service won't start are the one you just got and the "it started but then stopped" one, which usually means it threw an exception. Yours usually implies a bad loop or an overly long sleep if you're writing a "wake up and see if it's midnight yet" kind of service. But really, running it under the debugger from a test harness is the best way to gain insight into what's happening.

Related Topic