I’ve got a Windows Service that runs BackgroundWorker‘s, and I’m wondering if I’m doing the right thing when I stop my Windows Service.
Is it enough to:
- Let the
BackgroundWorker1_DoWorkmethod complete (I have a while loop in it now, doing some tasks) - Set the variable that holds the reference to the
BackgroundWorker, tonull
Is there some kind of Dispose() method I need to call (In the same way the Timer class has Timer.Dispose();)?
Frankly, when you stop your windows service – it really doesn’t matter. Your win32 process is terminated, so its not strictly necessary to clean up your IDisposables. Any unmanaged resources will have a finalizer that will still run.
That said, it’s normal to have a class level background worker that gets disposed when e service class does. Not necessary, but it’s always good to be clean.