المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Wierd DataGridView processing with a thread



C# Programming
05-07-2009, 12:14 PM
I have a DGV with checkboxes, a method processes each row and when complete unchecks the row.

This works fine, click the button and the form freezes and returns sometime later with all the boxes unchecked.

Now I introduce a separate thread to do the processing, split out the UI update and use the following to uncheck each row as it completes.

this.BeginInvoke((MethodInvoker)delegate
{
// this will be on main thread
UpdateGrid(oRow, iRecords);
});

private void UpdateGrid(DataGridViewRow oRow, int iRecords)
{
oRow.Cells["Records"].Value = iRecords;
oRow.Cells["Sel"].Value = false;
}


This works fine EXCEPT the first row (which happens to be selected but this is irrelevant) does not uncheck.

Slap a break point on and the index is hit and the first row is unchecked properly so I hit F5. Now the 2nd row is left checked. Seems there is an interaction between the debugger and the thread processing.

Has anyone else seen this type of behaviour?


Never underestimate the power of human stupidity
RAH