views:

2382

answers:

4

I have a windows service that is failing to start, giving an error "Error 1053: The service did not respond to the start or control request in a timely fashion".

Running the service in my debugger works fine, and if I double click on the the service .exe on the remote machine a console window pops up and continues to run without problem - I can even see log messages showing me that the program is processing everything the way it should be.

The service had been running fine previously, though this is my first time, personally, trying to deploy it with the most recent changes made to the program. I've evaluated those changes and cant figure out how they might cause this problem, particuarly since everything runs fine when not started as a service.

The StartRoutine() method of the service impelmentation is empty, so should be returning in a "timely fashion".

I've checked the event logs on the computer, and it doesn't give any additional information other than it didn't hear back from the service in the 30 second requisite time frame.

Since it works on my machine, and as a double-clicked executable, how would I go about figuring out why it fails as a service?

Oh, and it's .NET 2.0, so it shouldn't be affected by the 1.1 framework bug that exhibited this symptom (http://support.microsoft.com/kb/839174)

The box is a windows server 2003 R2 machine running SP2.

+2  A: 

Could be a number of things and it might help to get a stack trace on the machine exhibiting the problem. There are a number of ways to do this but the point is that you have to see where this is failing in the code.

You can do this with remote debugging, but a simple thing might be to just log to the event logger, or file log if you have that. Literally, putting "WriteLine("At class::function()") throughout portions of the code to see if you've made it there.

This will at least get you looking in the right direction (which ultimately is the code).

Update:

See Microsoft's How to Debug Windows Services article for details in troubleshooting startup problems using WinDbg.

This related question details nice ways to debug services that are written in .NET.

Scott Saad
A: 

I agree with Scott, the easiest way to find out what's happening is to put some traces in the start-up code (maybe it doesn't even come to your start-up code).

If this doesn't help, you can post your code here so others can take a look.

Igor Brejc
A: 

perhaps lacking some dependence, try this :
- deregister your service
- register again

If fail at register means that lack an module.

lsalamon
A: 

If the StartRoutine is empty, you are probably starting it somewhere else.

IIRC you need to fire off a worker thread, and then return from StartRoutine.

leppie
It looks like the code is executed by hooking the ServiceBase.Elapsed event, which is hooked in the constructor (it was doing this before as well, when it was working)
Matt

related questions