Which cross threading invoke function is better for a control that is inherited?
Posted
by Stevoni
on Stack Overflow
See other posts from Stack Overflow
or by Stevoni
Published on 2009-11-09T14:42:45Z
Indexed on
2010/04/17
1:03 UTC
Read the original article
Hit count: 377
I have a relatively simple question regarding the best way to call the DataGridView.Rows.Add function when it is inherited into the current control. Which is the best way to make the call to the inherited control? Call it directly in the invoke or call it using recursive-like function? They both seem to produce the same result, a row gets added and the quantity is returned, but which is the most efficient?
The delegate: Private Delegate Function ReturnDelegate() As Object
The two ways are:
A)
Private Overloads Function AddRow() As Integer
If InvokeRequired Then
Return CInt(Invoke(New ReturnDelegate(AddressOf AddRow)))
Else
Return Rows.Add()
End If
End Function
Or
B)
Private Function RowsAdd() As Integer
If Me.InvokeRequired Then
Return CInt(Me.Invoke(New ReturnDelegate(AddressOf MyBase.Rows.Add)))
Else
Return MyBase.Rows.Add
End If
End Function
© Stack Overflow or respective owner