title: Update datagridview from background thread odd behavior
body: <p>I have some data, and I update it in a task: The app is a hack at the moment for an idea so apologies for the code.</p>
  
  <pre><code>Task.Factory.StartNew(() =&gt;
      {
          dataGridView1.BeginInvoke((Action)(() =&gt;
              {
                  dataGridView1.SuspendLayout();
              }));
  
          dataSet1.Reset();
          da.Fill(dataSet1);
  
          dataGridView1.BeginInvoke((Action)(() =&gt;
              {
                  dataGridView1.DataSource = dataSet1.Tables[0];
                  dataGridView1.Columns[0].Visible = false;
                  dataGridView1.Columns[1].Width = 50;
                  dataGridView1.ResumeLayout();
              }));
      }
      ).ContinueWith(task =&gt;
          {
              if (dataSet1.Tables[0].Rows.Count &gt; 0)
              {
                  if (lastcount != dataSet1.Tables[0].Rows.Count)
                  {
                      lastcount = dataSet1.Tables[0].Rows.Count;
                      if (lastcount == 0)
                      {
                          NotifyWithMessage("The items have been cleared", "Items cleared");
                      }
                      else
                      {
                          NotifyWithMessage(String.Format("There are {0} new items in your monitor", dataSet1.Tables[0].Rows.Count));
                      }
                  }
              }
          }
      );
  </code></pre>
  
  <p>Now, the code fundamentally works. No errors, which is nice..</p>
  
  <p>When it was updated outside a task, there was no flashing of the datavgridview at all, when I run it in debug, it's very minor and well within acceptable for the hack.. the moment I run it outside debugging... it's terribly obvious! The suspend and resume layouts have not made any difference at all. I need the code in the thread, because the UI is lumpy responsive without - whereas it's acceptable, but it has the bad refresh now.</p>
  
  <p>My Datagridview is custom coloured depending on cell colours, but, I just cant see why there's the difference between debug and release, I'd expect the performance the other way round!</p>
  
  <p>(I tried Invoke and BeginInvoke...)</p>
  
  <p>I looked at <em><a href="https://stackoverflow.com/questions/118528/horrible-redraw-performance-of-the-datagridview-on-one-of-my-two-screens">Horrible redraw performance of the DataGridView on one of my two screens</a></em></p>
  
  <p>And under debug, this doesn't flicker at all, not even a bit... Under release conditions, there is a ridiculous flicker...</p>
  
  <p>What can I do?</p>