I am writing a windows service in .net 2.0.
What should I do in the method OnStart()if for some reason I do not want my service to start? Is it possible to just call the Stop()base class ( ServiceBase) method ? I tried this and get some funny memory access exceptions. Do I need to start a separate thread to call a method Stop()?
OnStart()
Stop()
ServiceBase
Why would you want to do that? If there is an error, write it to the event log and throw an exception. Your service will not start and the user will be informed that something bad has happened.
ServiceController , .
You can use Environment.FailFast () . Just keep in mind that it ignores try-catch-finally blocks.