.net Windows Service Won't Start - Timeout

J

jmagaram

I've written a .net Windows service in C#. It works most of the time for most
people. It is configured to automatically start when Windows boots. Sometimes
it fails to start on Windows XP during boot. All I know is that it is timing
out. But no useful details appear in the event log, not even my first
EventLog message in OnStart. How can I figure out why it isn't starting? How
can I fix this?

My ServiceBase constructor just sets a few properties. The first few lines
of OnStart are...

EventLogTraceListener logListener = new
EventLogTraceListener("TimesUpKidz");
Trace.Listeners.Add(logListener);
try { Trace.WriteLine("Starting"); } catch { }

This message does not show up in the EventLog. The log is nearly empty, so
there is no chance of it being full and losing messages.

These are two errors in the System EventLog:

Timeout (30000 milliseconds) waiting for the TimesUpKidz service to
connect.
Service Control Manager Error Event ID 7009

The TimesUpKidz service failed to start due to the following error:
The service did not respond to the start or control request in a timely
fashion.
Service Control Manager Error Event ID 7000

One theory I have is that maybe it is taking a very long time to load the
..net plumbing. I made my service dependent on:

winmgmt (Windows Management Instrumentation)
termservice (Terminal Services)

The service uses Remoting.
 
J

Jurjen de Groot

Have you tried to write your log to a regular file instead of to the
eventlog ?
Just to see if maybe the eventlog is the problem, maybe it's unavailable.

Jurjen.
 
P

Paul Montgumdrop

jmagaram said:
I've written a .net Windows service in C#. It works most of the time for most
people. It is configured to automatically start when Windows boots. Sometimes
it fails to start on Windows XP during boot. All I know is that it is timing
out. But no useful details appear in the event log, not even my first
EventLog message in OnStart. How can I figure out why it isn't starting? How
can I fix this?

You might want to use the example in the link for creating an Eventlog
and writing events to it.

http://support.microsoft.com/kb/307024

One method to debug the NT service is to enable the Messenger Service on XP.

With MSG service enabled, you can put code in the NT service like in the
Onstart(s) or anywhere really, using the NET Send command, format a
message, shell out to the Command Prompt and issue the Net Send with
message and machine-name. The NET Send will pop-up a message box on the
console screen on the machine with an OK reply button.

So you can pop messages to yourself like Here1 Here2 Here3 to pinpoint
where the program is going down.
 
J

John Vottero

jmagaram said:
I've written a .net Windows service in C#. It works most of the time for
most
people. It is configured to automatically start when Windows boots.
Sometimes
it fails to start on Windows XP during boot. All I know is that it is
timing
out. But no useful details appear in the event log, not even my first
EventLog message in OnStart. How can I figure out why it isn't starting?
How
can I fix this?

Do you digitally sign your executable? If so, you may have this problem:

http://support.microsoft.com/kb/936707

To increase the service startup timeout value, see:

http://support.microsoft.com/kb/922918
 
J

jmagaram

Assuming there is something wrong with the event log, I've tried logging to a
file. The first line of Main is:

File.AppendAllText(@"c:\log.txt", "getting started");

This log file does not get created during restart of the operating system.
If I launch the service manually later, it does get logged. I'm really
stumped here. For some reason my service can't get started and times out
during reboot but not when I start it manually later.
 
J

jmagaram

no i haven't solved it. i put the writeline at the first line of Main -
before OnStart - and that didn't get executed. i can occassionally reproduce
the problem after installing AVG antivirus and rebooting several times in a
row. i have tried using ngen to improve startup time, but no success so far.
i don't understand how to pick a baseaddress that is guaranteed not to
conflict with another application, and my program using xml serialization
anyway so the mscorjit(?) gets loaded anyway. i am stumped. let me know if
you make progress on this. at this point i am telling customers to increase
the service timeout to 45 seconds - there is a way to set this in the
registry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top