对于继承的控件来说,哪种跨线程调用函数更好?
我有一个相对简单的问题,关于在继承到当前控件时调用 DataGridView.Rows.Add 函数的最佳方法。调用继承控件的最佳方法是什么?直接在调用中调用它还是使用类似递归的函数调用它?它们似乎都产生相同的结果,添加一行并返回数量,但哪一个最有效?
委托:私有委托函数 ReturnDelegate() As Object
两种方法是:
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
或
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常我会通过在一系列更新周围放置 BeginUpdate() EndUpdate() 块来提高效率。
Usually I take care of efficiency by placing BeginUpdate() EndUpdate() block around my series of updates.