title: C# Opening a Modal Form in a class with background worker
body: <p>I'm trying to create a class, that can be used anywhere, that runs a background worker process, which if running, will open a modal form that shows it's progress and other forms aren't usable but having difficulty working it out. Thought I might be able to do the following, but doesn't seem to work. Any other ideas?</p>
  
  <p>I might be going completely the wrong way about it, but here is my cut down code:</p>
  
  <pre><code>public partial class Main : Form
  {
      public Main()
      {
          // load the database
          Database.Load(this);
  
          InitializeComponent();
      }
  }
  
  namespace Blah.Common
  {
  public static class Database
  {
      private static Progress progressForm = new Progress();
      public static void Load(Form parentForm)
      {
          bw.WorkerReportsProgress = true;
          bw.WorkerSupportsCancellation = true;
  
          bw.DoWork += (obj, e) =&gt; bw_DoWork(parentForm);
          bw.RunWorkerAsync();
      }
  
      private static void bw_DoWork(Form parentForm)
      {
          progressForm.ShowDialog(parentForm);
          progressForm.UpdateLabel("Loading...");
  
          doHeavyProcess();
          progressForm.Dispose()
      }
   }
   }
  </code></pre>