Today I noticed that my .NET service never stopped correctly - the SCM always threw a warning before placing it in the "stop pending" state. It turns out that even after exiting OnStop, I still had an extra thread hanging around from a WCF ServiceHost I had opened and then let go out of scope before closing.
The listening thread from the ServiceHost kept the service process alive, which prevented a smooth stop of the service. The fix was to keep the ServiceHost in scope (as an instance member) and then close it in OnStop.
No comments:
Post a Comment