Stopping Windows Service programmatically
Posted on 2004-08-16
I have a windows service (c#) that I need to stop programmatically from within itself.
I know normally I can do something like this:
System.ServiceProcess.ServiceController mySC = new ServiceController(this.ServiceName);
However, I need to be able to instruct the service to stop while it is still in the OnStart process - specifically, has a state of StartPending.
The service Im writing has a number of config files upon which it is absolutely dependant, and must stop regardless of what else its doing, should a file be missing or corrupt...