C. Ross C. Ross - 3 months ago 47
C# Question

Handle exception on service startup

I'm writing a series of Windows services. I want them to fail if errors are thrown during startup (in

method). I had assumed that merely throwing an error in
would do this, but I'm finding that instead it "Starts" and presents me with a message stating "The service has started, but is inactive. Is this correct?" (Paraphrase). How do I handle the error so it actually fails to start the service?


if you are running .NET 2.0 or higher, you can use ServiceBase.Stop to stop the service from OnStart. Otherwise call Stop from a new thread.

ref [devnewsgroups] (http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework/topic50404.aspx)

(news group gone)