views:

73

answers:

2

My automatically starting windows service fails to start only on reboot. I have a windows service created in C# and installed via a Wix created installer. The service is set up to start automatically. The service is installed and run under the NT AUTHORITY\NETWORK SERVICE. When the service is started, it first makes an external web services call.

In Windows 7 I can set the service to be Automatic - Delayed start and the service will start on reboot no problem. However, this option is not available in Windows XP, and when set to Automatic start, the service fails due to

A timeout was reached (30000 milliseconds) while waiting for the MyService service to connect.

If I try to start manually after the login process, the service starts fine, it is only when the service tries to auto start on reboot that there is an issue, leading me to believe there are dependency services that I need to add to my service for it to start correctly.

Can anyone point me to the correct dependencies or an alternative approach?

+4  A: 

You likely have a race condition with a dependency. You could probably patch around this by configuring your service to have a dependency on another service ( say tcp/ip ) but what I'd really do is rewrite your service to not need to make this call during the criticial execution path of startup. It should instead periodically attempt to make the webservice call at a later point and log useful messages or send messages to a taskbar utility or similar if there is a problem that needs to be addressed.

Christopher Painter
I've thought about doing both. Problem is that the call is made to retrieve remote configuration settings and as such is built in to the Settings as an extension of SettingsProvider.
aurealus
Sorry, but it needs to be done. The basic design is fragile at best. Web is stateless and to assume that it is anything else is wrong.
Christopher Painter
I took your advice and made my OnStart() method do the bare minimum functionality and start a Timer that executes later to pull down the configuration settings and initialize the service functionality.
aurealus
+2  A: 

Look at question http://stackoverflow.com/questions/1986292, it has a solution to your problem.

qbeuek