title: BackgroundWorker - Cross-thread operation not valid
body: <p>I have a winform application (one form), on this form there is a RichTextBox. In the constructor of this form I create an instance of the class <code>MyClass</code>. In the “Form_Load” I call the method <code>Initialisation</code> from <code>MyClass</code> instance.</p>
  
  <p><strong>In the form constructor</strong></p>
  
  <pre><code>myClass = new MyClass(RichTextBox richTextBox);
  </code></pre>
  
  <p><strong>In the Form_Load</strong></p>
  
  <pre><code>myClass.Initialisation();
  </code></pre>
  
  <p>In the <code>Initialisation</code> method, in a loop, I read some parmeters  do other stuffs. To not freeze the application (because some operation can take a while, some seconds), I use a <code>BackgroundWorker</code>. I use it like this (see code below). </p>
  
  <p>When I execute, I get this error : <em>Cross-thread operation not valid: Control ‘richTextBox’
  accessed from a thread other than the thread it was created on</em>. </p>
  
  <p>Could you tell me how solve this ? Work perfect when I don't access the <code>richTextBox</code></p>
  
  <pre><code>public Class MyClass
  {
      static BackgroundWorker _bw;
      public MyClass()
      {
          _bw = new BackgroundWorker
          {
              WorkerReportsProgress = true,
              WorkerSupportsCancellation = true
          };
          _bw.DoWork += bw_DoWork;
          _bw.ProgressChanged += bw_ProgressChanged;
          _bw.RunWorkerCompleted += bw_RunWorkerCompleted;
      }
      static void bw_DoWork(object sender, DoWorkEventArgs e)
      {
          foreach (....)
          {
              if (....)
              {
                  richtextBox.Text.AppendText("MyText");
              }
          }
          e.Result = true;
      }
      static void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e){}
      static void bw_ProgressChanged(object sender, ProgressChangedEventArgs e){}
  }
  </code></pre>