title: Passing object from backgroundworker to main thread
body: <p>I have a WPF application that executes external programs to process media files, and so that the GUI doesn't freeze when the media files are being processed, I execute the process on a separate thread through backgroundworker.</p>
  
  <pre><code>        private void BackgroundWorkerExecProcess(Process process)
      {
          BackgroundWorker worker = new BackgroundWorker();
          worker.WorkerReportsProgress = false;
          worker.DoWork += DoWork;
          worker.RunWorkerCompleted += WorkerCompleted;
          worker.RunWorkerAsync(process);
      }
      void DoWork(object sender, DoWorkEventArgs e)
      {
          BackgroundWorker worker = sender as BackgroundWorker;
          Process process = e.Argument as Process;
          process.Start();
          string stderr = process.StandardError.ReadToEnd();
          //I want to display stderr on main thread
          process.WaitForExit();
      }
      void WorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
      {
          //some code to update gui telling user that process has finished
      }
  </code></pre>
  
  <p>so, if there is something printed to stderr, I can see it in the debugger, but if I try to do anything with the string stderr, such as if I have a textbox called "_tbLog" and did</p>
  
  <pre><code>_tbLog.Text+=stderr;    
  </code></pre>
  
  <p>I get an error from the compiler about them being on separate threads. is there a way to pass the object from the worker thread to the main thread?</p>