title: Invoke delegate method name with parameter
body: <p>Trying to have a setup where I have a <code>BackgroundWorker</code> running behind the scenes, and then updating its progress on a separate modal dialog as it completes each step. The problem is, of course, that trying to update the progress dialog from the <code>BackgroundWorker</code> thread causes cross-thread issues.</p>
  
  <p>Code: (problematic lines have comments surrounded with <code>***</code>)</p>
  
  <pre><code>public void StartProcess()
  {
      // dialog that shows a simple marquee progress bar and a message
      ProgressDialog progress = new ProgressDialog("Starting operation...");
  
      // create background worker thread
      BackgroundWorker bw = new BackgroundWorker();
      bw.WorkerSupportsCancellation = true;
      bw.WorkerReportsProgress = true;
      bw.DoWork += Bw_DoWork;
      bw.RunWorkerCompleted += Bw_RunWorkerCompleted;
  
      if(!bw.IsBusy)
      {
          bw.RunWorkerAsync();
          progress.ShowDialog();
      }
  }
  
  private void Bw_DoWork(object sender, DoWorkEventArgs e)
  {
      BackgroundWorker bw = sender as BackgroundWorker;
      if(bw.CancellationPending)
      {
          e.Cancel = true;
      }
      else
      {
          // perform step 1
  
          // *** this line generates cross-thread problems ***
          progress.Message = "Performing step 2...";
  
          // etc...
      }
  }
  </code></pre>
  
  <p>And here's the code for the progress dialog:</p>
  
  <pre><code>public partial class ProgressDialog : Form
  {
      public string Message
      {
          get
          {
              return lblMessage.Text;
          }
          set
          {
              if(lblMessage.InvokeRequired)
              {
                  // *** not sure how to invoke this by passing the "value" parameter ***
                  // *** returns a TargetParameterCountException ***
                  // *** trying to pass "value" in results in "Method name expected" error ***
                  lblMessage.Invoke(new UpdateMessageDelegate(SetMessage));
              }
          }
      }
  
      private delegate void UpdateMessageDelegate(string s);
  
      private void SetMessage(string s)
      {
          lblMessage.Text = s;
      }
  }
  </code></pre>
  
  <p>How can I safely change the text value of the label by using its <code>set</code> method and the implicit <code>value</code> parameter?</p>