title: Control 'dataGridView1' accessed from a thread other than the thread it was created on
body: <p>I have a windows form which is taking forever to load data into my datagridview.</p>
  
  <p>So I thought Id use a thread but I keep getting the error:</p>
  
  <p>"Cross-thread operation not valid: Control 'dataGridView1' accessed from a thread other than the thread it was created on."</p>
  
  <p>Here is my code:</p>
  
  <pre><code>private void Form1_Load(object sender, EventArgs e)
      {
         //lblFormDisplayStatus.Text = "Retrieving Data from Database";
  
          if (isProcessRunning)
          {
              MessageBox.Show("A process is already running.");
              return;
          }
  
          SetIndeterminate(true);
  
          Thread backgroundThread = new Thread(
              new ThreadStart(() =&gt;
              {
                  isProcessRunning = true;
  
                  Thread.Sleep(5000);
  
                  //MessageBox.Show("Thread completed!");                    
  
                  BeginInvoke(new Action(() =&gt; Close()));
  
                 RunProgram(); // the method responsible for binding the data to datagrid         
  
                  isProcessRunning = false;
              }
          ));
          backgroundThread.Start();
  
          ShowDialog();           
  
      }
  </code></pre>
  
  <p>pls put me out of my misery and show me where I am going wrong</p>
  
  <p>thanks</p>