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.
Task.Factory.StartNew(() =>
{
dataGridView1.BeginInvoke((Action)(() =>
{
dataGridView1.SuspendLayout();
}));
dataSet1.Reset();
da.Fill(dataSet1);
dataGridView1.BeginInvoke((Action)(() =>
{
dataGridView1.DataSource = dataSet1.Tables[0];
dataGridView1.Columns[0].Visible = false;
dataGridView1.Columns[1].Width = 50;
dataGridView1.ResumeLayout();
}));
}
).ContinueWith(task =>
{
if (dataSet1.Tables[0].Rows.Count > 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));
}
}
}
}
);
Now, the code fundamentally works. No errors, which is nice..
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.
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!
(I tried Invoke and BeginInvoke…)
I looked at Horrible redraw performance of the DataGridView on one of my two screens
And under debug, this doesn’t flicker at all, not even a bit… Under release conditions, there is a ridiculous flicker…
What can I do?
In the end heres what I did:
I rean the query into a new dataset, if the count was the same, then I didnt update the grid, if the count had changed I did.