How to get a C# service to restart?

2006-03-24 16:13:08 by Kjell-Åke Gafvelin

I have been trying for a while to figure out how to get a C# service to restart using the recovery settings for the service. It doesn't help if I set the ExitCode to -1 or any other values (I haven't tried them all, but you get the picture?) or if I throw exceptions, it still refuses to restart!

In the OnStart override I start a new thread which will do all processing and if it fails I set the ExitCode to -1, ERROR_SERVICE_SPECIFIC_ERROR, ERROR_EXCEPTION_IN_SERVICE or ERROR_INTERNAL_ERROR and then call the Stop method on ServiceBase.

If you have any suggestions please drop me a mail!