BackgroundWorker comes from Component. The component implements the IDisposable interface. This in turn causes BackgroundWorker to inherit the Dispose () method.
Retrieving from a Component is a convenience for Windows Forms programmers; they can drop BGW from the toolbar into the form. Components in general are more likely to have something to dispose of. Windows Forms Designer will take care of this automatically, look in the Designer.cs file for the form for the "components" field. Its automatically generated Dispose () method calls the Dispose () method for all components.
However, BackgroundWorker does not actually have a member that requires recycling. It does not override Dispose (). Its basic implementation, Component.Dispose (), only guarantees that the component will be removed from the "components" collection. And raise the Disposed event. But otherwise he does not manage anything.
In short: if you dumped BGW on the form, then everything takes care automatically, you do not need to help. If you did not drop it on the form, this is not an element in the component collection, and nothing needs to be done.
You do not need to call Dispose ().
Hans Passant Mar 30 '10 at 1:53 2010-03-30 01:53
source share