title: Update C# datagridviews in separate thread
body: <p>I have a windows form with a datagridview and some buttons. One of the buttons when clicked will call a method called <code>loadMyData()</code> that reads some data from a csv and puts them in three datagridviews in the form. </p>
  
  <p>The code is something like this:</p>
  
  <pre><code>public partial class NewForm : Form
  {
  
      private void loadData_Click_1(object sender, EventArgs e) // load market data, create a base copy and update gridview
      {
          ThreadStart thread1Start = new ThreadStart(loadMyData);
          Thread t1 = new Thread(thread1Start);
          t1.Start();          
      }
  
      public void loadMyData()
      {
      dataMap = dataLoader.newLoadTheData(dataMap, grid1, grid2) 
  
  
      }
  }
  </code></pre>
  
  <p>where <code>dataLoader.newLoadTheData</code> is a static method that takes as input my datagridviews (grid1, grid2) and a dictionary (dataMap). The method simply reads some data from a csv and put the numbers in the 2 datagridviews. These are updated from this method and an updated dictionary (dataMap) is also returned by the method. It all works fine when the method <code>loadMyData()</code> is executed normally but I get this error when I execute it as thread: </p>
  
  <blockquote>
    <p>Cross-thread operation not valid: Control 'grid1' accessed from a
    thread other than the thread it was created on.</p>
  </blockquote>
  
  <p>I realize that I might be using something like "invoke" but I really can't find a clear example that shows how to do this in my case. Can anyone help with tjis situation? How should I change the code to make it work? </p>