I have seen many questions on SO regarding the disposal of a BackgroundWorker in a Windows Forms application, and it appears that the consensus is that they do not need to be manually disposed in most situations. However, I have a question regarding how to handle a UserComponent that is being disposed when a BackgroundWorker is actually running. (IsBusy
returns true) Should this situation be handled in any particular way?
For example I have a UserControl (panel-like object) that a user can enter settings information. It contains a BackgroundWorker in it that saves a user's configuration. When the panel looses focus (Leave event) it spins up the BackgroundWorker if it's not already running to save the configuration to file if a change is detected. Since the Leave event may also be the user changing to another screen this panel will now be disposed. If the BackgroundWorker is still running do I need to handle this in the Dispose method of the UserComponent itself?