title: Cross thread exception
body: <p>I am having a problem for a while</p>
  
  <p>this line:</p>
  
  <pre><code>txtPastes.Text = (string)e.UserState;
  </code></pre>
  
  <p>throws a cross thread exception and I didn't find any solution</p>
  
  <p><code>txtPastes</code> - textbox</p>
  
  <p><code>GuiUpdate</code> - BackgroundWorker</p>
  
  <p><code>lstAllPastes</code> - list of string</p>
  
  <pre><code>    private void GuiUpdate_DoWork(object sender, DoWorkEventArgs e)
      {
          while (true)
          {
              while (lstAllPastes.Count == 0) ;
  
              for (int i = 0; i &lt; lstAllPastes[0].Length; i++)
              {
                  GuiUpdate.ReportProgress(0, lstAllPastes[0].Substring(0, i));
                  Thread.Sleep(1);
              }
              lstAllPastes.RemoveAt(0);
          }
      }
  
      private void GuiUpdate_ProgressChanged(object sender, ProgressChangedEventArgs e)
      {
          txtPastes.Text = (string)e.UserState;
      }
  
      private void GuiUpdate_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
      {
  
      }
  </code></pre>