Windows service hanging on exit

Viewed 24

I have a Windows service that I wrote. In a certain, rare instances I need to have the service restart itself. If I call "System.Environment.Exit(1)" it will cause the service to exit and then Windows will start it back up, which is exactly what I need to do. The problem is sometimes, not always, the service hangs when I do this this. And at that point even going into services and trying to stop the service doesn't work. The only way is to force quit it through task manager. I've made sure I'm exiting all threads and cleaning everything up. And all threads are started with "IsBackground=true" anyway, so those shouldn't be an issue.

I can't see anything else that could be preventing it from exiting. Does anyone have any idea what else could be the problem? Or is there a better way I can have my service restart itself without having this problem?

Thanks

0 Answers
Related