Enviroment.Exit will close the process that is wrapped by the service.
Therefore, calling it will not call the onStop() method.
You can call the method yourself, instead of calling Exit
You can use the following code to call SCM stop
System.ServiceProcess.ServiceController svc = new System.ServiceProcess.ServiceController("NameOfYourService"); svc.Stop();
Ofiris
source share