title: How to use a BackgroundWorker to update multiple labels?
body: <p>This is a follow up question to <a href="https://stackoverflow.com/questions/12168174/updating-a-dialog-from-another-form">Updating a dialog from another form</a> (The code and screenshots can be found there)</p>
  
  <p>To solve my GUI hanging problem I received 2 recommendations:</p>
  
  <ul>
  <li><p>Using <code>Application.DoEvents()</code></p></li>
  <li><p>Using a <code>BackgroundWorker</code></p></li>
  </ul>
  
  <p>The DoEvents() approach works, however it has been pointed out that I should not use it. Indeed, I notice that the GUI updates correctly but is unresponsive for short times.</p>
  
  <p>That's why I want to use a BackgroundWorker and have read up on it.</p>
  
  <p>I don't understand how I would implement it so that it can be used to update the 4 labels in my example code separately, though.
  I want to show the progress (and update 4 dialog labels) as the program successfully finishes one job. The BackgroundWorker has only 1 <code>DoWork()</code> though. I have tried to use the <code>e.Argument</code> of the <code>DoWorkEventArgs</code> to differentiate between the different update methods but that attempt had failed.</p>
  
  <pre><code>public partial class BackgroundWorkerImportStatusDialog : Form
  {
      private BackgroundWorker dialogWorker = new BackgroundWorker();
  
      private string path;
      private string clientName;
  
      public BackgroundWorkerImportStatusDialog()
      {
          InitializeComponent();
      }
  
      public void updateFileStatus(string path)
      {
          this.path = path;
  
          dialogWorker = new BackgroundWorker();
          dialogWorker.DoWork += new DoWorkEventHandler(updateLabels);
          dialogWorker.RunWorkerAsync(UpdateComponent.FileStatus);
  
      }
  
      public void updatePrintStatus()
      {
          dialogWorker = new BackgroundWorker();
          dialogWorker.DoWork += new DoWorkEventHandler(updateLabels);
          dialogWorker.RunWorkerAsync(UpdateComponent.PrintStatus);
      }
  
      public void updateImportStatus(string clientName)
      {
          this.clientName = clientName;
  
          dialogWorker = new BackgroundWorker();
          dialogWorker.DoWork += new DoWorkEventHandler(updateLabels);
          dialogWorker.RunWorkerAsync(UpdateComponent.ImportStatus);
      }
  
      public void updateArchiveStatus()
      {
          dialogWorker = new BackgroundWorker();
          dialogWorker.DoWork += new DoWorkEventHandler(updateLabels);
          dialogWorker.RunWorkerAsync(UpdateComponent.ArchiveStatus);
      }
  
      private void updateLabels(object sender, DoWorkEventArgs e)
      {
          MessageBox.Show(e.Argument.ToString());
          if ((UpdateComponent) e.Argument == UpdateComponent.FileStatus)
          {
              t_filename.Text = path;
          }
          if ((UpdateComponent) e.Argument == UpdateComponent.PrintStatus)
          {
              t_printed.Text = "sent to printer";
          }
          if ((UpdateComponent) e.Argument == UpdateComponent.ImportStatus)
          {
              t_client.Text = clientName;
          }
          if ((UpdateComponent) e.Argument == UpdateComponent.ArchiveStatus)
          {
              t_archived.Text = "archived";
          }
      }
  
      public enum UpdateComponent { FileStatus, PrintStatus, ImportStatus, ArchiveStatus}
  </code></pre>
  
  <p>And I can't imagine having 4 BackgroundWorkers for this pretty trivial dialog is the solution.</p>