I understand that .NET is multi-threaded and that is a good thing, but I continually run into issues when I have a background worker for example that is updating some control on my form and I have to do:
Private Sub SetRowCellBoolValueThreadSafe(ByVal row As Integer, ByVal col As Integer, ByVal value As Boolean)
If dgvDatabase.InvokeRequired Then
Dim d As New SetRowCellBoolValueCallback(AddressOf SetRowCellBoolValue)
Me.Invoke(d, New Object() {row, col, value})
Else
SetRowCellBoolValue(row, col, value)
End If
End Sub
Delegate Sub SetRowCellBoolValueCallback(ByVal row As Integer, ByVal col As Integer, ByVal value As Boolean)
Private Sub SetRowCellBoolValue(ByVal row As Integer, ByVal col As Integer, ByVal value As Boolean)
dgvDatabase.Rows(row).Cells(col).Value = value
End Sub
My question is why is this not built into the framework - surely if I am trying to update a DataGridView
it should be intelligent enough to know when the update is from another thread and it could do all the above itself?