0
votes

I have a few Windows services (all written in C#) that all show the same strange behaviour. I have them set to delayed auto start so that they get started after the boot (delayed because well they are not critical). They all host WCF services as parts of Client-Server applications and were installed using WiX if that matters.

I noticed that sometimes they just don't start. If you look into the Services window fast enough after the OS is ready they have status "Starting". If you then refresh the view they are no longer starting but not "Started" either. You can then start them manually without any problem whatsoever.

This produces no error messages and no log entrys. And to make it even better this only occurs if the machine has been shut down and turned on again. Reboot works perfectly fine every time (tried it about 20 times on two different machines)

If you set the failure actions to restart the service after failure it seems it will eventually start the service successfully but surely this can not be the ideal solution.

OSs are Windows 7 and WinServer 2008 R2

What am I missing here? Why do they fail to be started automatically(the first time at least)? And why does it make a difference if the computer boots following a reboot or a shutdown?

EDIT: I was wrong about the failure actions. The did not fix the problem.

EDIT 2: I have added exception handling around everything to log possible exceptions. But so far no exceptions have been logged.

2

2 Answers

2
votes

Might it be the WCF Services take a long time to start? afaik, the windows service has to come up in a certain time (best practices is 30 seconds, technical limit I don't know) to not time out. That could explain why your service is in status "starting" but does not start.

0
votes

Please see my answer from the duplicate. A windows service typically shouldn't have access to the desktop for security reasons. But it certainly should have a good amount of logging in it. You probably have a race condition. The only thing you could do about this in WiX would be to express a dependency on another service to get the service control manager to wait awhile before starting the service. But it really would be better if your code was more robust. An example would be the OnStart event fire up a background worker process and then return success. The background thread could then keep attempting to host the WCF endpoint and everything do a fair amount of logging in the process.