title: Cross-thread operation not valid: Control 'progressBar1' accessed from a thread other than the thread it was created on
body: <p>I couldn't find an answer for this:</p>
  
  <blockquote>
    <p>"Cross-thread operation not valid: Control 'progressBar1' accessed
    from a thread other than the thread it was created on."</p>
  </blockquote>
  
  <p>This is my code:</p>
  
  <pre><code>        private void buttonStart_Click(object sender, EventArgs e)
          {
              ClassCopy cb = new ClassCopy();
              cb.startCopy(textBoxSrc.Text, textBoxDest.Text, true);
  
              th = new Thread(loading);
              th.Start();
  
          }
  
          private loading()
          {
              for (int i = 0; i &lt; 100; i++)
              {
                  if (progressBar1.InvokeRequired)
                      progressBar1.Invoke(new Action(loading));
                  else
                      progressBar1.Value = i;
              }
          }
  </code></pre>