title: C# why does using BeginInvoke delegate update datagridview with only the last of multiple entries
body: <p>I'm having an issue while updating a datagridview of on WinForm.  I set the DataSource of the datagridview to a bindinglist like so:</p>
  
  <pre><code>List&lt;Data&gt; rows = new List&lt;Data&gt;();
  
  BindingList&lt;Data&gt; list = new BindingList&lt;Data&gt;(rows);
  
  this.dataBindingSource.DataSource = list;
  this.dataGridView3.DataSource = this.dataBindingSource;
  </code></pre>
  
  <p>In a different method within the class I am adding to the datagridview by adding to bindinglist like so:</p>
  
  <pre><code>Data theData = new Data();
  
  ....
  //Data is an object with various getters and setters like
  theData.price = ...
  theData.qty = ...
  ....
  
  this.BeginInvoke((MethodInvoker)delegate() { list.Add(Data); });
  </code></pre>
  
  <p>This works fine when I make single calls to the method that is updating the binding list.
  But I have a situation where I am calling the method multiple times back to back from a different method like so:</p>
  
  <pre><code>updateRowMethod(....);
  updateRowMethod(....);
  </code></pre>
  
  <p>The two calls are providing different data for the update.  But now the datagridview inserts 2 new rows but both rows contain the same data and in both rows it displays only the data passed in the second method call.</p>
  
  <p>The method where rows are being added to the datagridview first updates a database with the data before adding it to the datagridview and on startup the datagridview is populated with data from the database.  Subsequently if I relaunch the application, the datagridview is populated with the correct data.  So the problem only occurs when viewing the new rows which are added while the application is currently running and being updated, the problem doesn't occur on restart and data is pulled from the DB.</p>
  
  <p>I have put in breakpoints and see that the BeginInvoke line which adds the data is correctly being called twice for the 2 method calls and both times the correct data is coming into that line, and it is adding 2 new rows but it is only displaying data from the second function call.</p>
  
  <p>I would greatly appreciate any insight you all may have.</p>
  
  <p>Thanks </p>