对于继承的控件来说,哪种跨线程调用函数更好?

发布于 2024-08-10 23:35:43 字数 695 浏览 1 评论 0原文

我有一个相对简单的问题,关于在继承到当前控件时调用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滥情哥ㄟ 2024-08-17 23:35:43

通常我会通过在一系列更新周围放置 BeginUpdate() EndUpdate() 块来提高效率。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文