title: C#: Do I need to dispose a BackgroundWorker created at runtime?
body: <p>I typically have code like this on a form:</p>
  
  <pre><code>    private void PerformLongRunningOperation()
      {
          BackgroundWorker worker = new BackgroundWorker();
  
          worker.DoWork += delegate
          {
              // perform long running operation here
          };
  
          worker.RunWorkerAsync();
      }
  </code></pre>
  
  <p>This means that I don't dispose the <code>BackgroundWorker</code>, whereas if I had added it by the form designer then I think it would get disposed.</p>
  
  <p>Will this cause any problems?  Is it more correct to declare a module-level <code>_saveWorker</code>, and then call <code>Dispose</code> on it from the form's dispose method?</p>