How do you have a service self terminate?
Environment.Exit will cause the app to start but the service stays running.
Any idea?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use the SCM to shut down your service from within the service itself:
Edit:
The other option is to call
ServiceBase.Stop()in your service – if you have access to yourServiceBasederived class instance that would be the cleaner way to go – in many cases it is cumbersome though having to pass this dependency around.If you have an uncaught exception I personally would just let the service crash (or log it and then
throw), which will leave a message in the event log detailing the termination reason. If you absolutely need to you can catch the Exception, and then callServiceBase.Stop().