title: C# background worker freezes UI when running a 2nd time
body: <p>In my UI, when a press a button, the following code is executed:</p>
  
  <pre><code>backgroundWorker1 = new BackgroundWorker();
  backgroundWorker1.WorkerSupportsCancellation = true;
  backgroundWorker1.WorkerReportsProgress = true;
  backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
  backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);
  backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
  backgroundWorker1.RunWorkerAsync();
  </code></pre>
  
  <p>This works great the first time. When I hit the button (which then becomes disabled), I can still move the window around and click stuff while the background task is executing. But when the background worker is done (button becomes enabled again) and I press it again, the background worker runs, but I no longer have control of the window.</p>
  
  <p>I have no idea why this doesn't work the second time. Is there something I need to do before or after the background worker runs to make sure it is not blocking the UI thread?</p>
  
  <p>Thanks!</p>
  
  <p><strong>Edit:</strong> In the backgroundworker ProgressChanged handler, I update a progress bar and text labels displaying how far along the background worker is. They are constantly updated and never freeze. But when I try and drag the window or click on other controls, they only respond periodically.</p>
  
  <p>The backgroundworker accesses an instance of a class that is a global variable in the UI thread. The idea was to instantiate the object, run a long function the object performs from inside the backgroundworker's DoWork, and then access the object after the backgroundworker has finished to view the results. Is this ok to do?</p>
  
  <p>Inside this object's function that is called in the backgroundworker's DoWork, a couple static classes are accessed. Will this cause any sort of threading issues?</p>