.NET windows service does not autostart

G

Guest

I have created a windows service in VS2005 .NET, which works well. The
service is set to "Automatic", however it does not autostart on bootup. The
eventlog shows the error "The service did not respond to the start or control
request in a timely fashion"

My service uses TCP/IP sockets, so I have specified "Tcpip" as a dependency
service (For some reason, the DependOnService shows up in the registry entry
for my service, but not in the services management MMC). My service also
tries to connect to a SQL server on a remote database at startup (I am using
ADO.NET).

Should I be adding any other DependOnServices?

I read a post about this error happening if the Application event log is
full, however, on my machine it is set to "overwrite events as needed", so I
dont think thats the issue.

Harv Hundal
 
C

Claes Bergefall

This error usually means that the startup code takes to long to execute.
Windows requires that services report back to the service control manager
periodically during startup (all this is hidden in the .NET classes). If
your startup code takes a long time, you will get the indicated error and
Windows will basically kill your process

Try moving your startup code to a separate thread or use the
RequestAdditionalTime method to indicate the expected time that your startup
code takes.

/claes
 
G

Guest

There is nothing in my service code that should take too long (not 30 seconds
in any case). It is instantiating a TcpListener object, and creating another
thread that waits for TCP client requests. Whan a TCP client connects,
another thread is spawned that trys to connect to a SQL Server database, and
any connection errors are being handled in my code.

I have changed the service's AutoLog property to false, and am now using the
EventLog object programatically to write to the Application Event Log from
the service's OnStart and OnStop event handlers. This seems to have resolved
the issue. Not sure whyit would make a difference, but it works (Microsoft
has a bug there they would like to tell us about?).

However, thanks for your suggestions Claes.

Harv
 

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