开发者

Which cross threading invoke function is better for a control that is inherited?

I have a relatively simple question regarding the best way to call the DataGridView.Rows.Add function when i开发者_JAVA技巧t 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


Usually I take care of efficiency by placing BeginUpdate() EndUpdate() block around my series of updates.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜