【问题标题】:Which cross threading invoke function is better for a control that is inherited?对于继承的控件,哪个跨线程调用函数更好?
【发布时间】:2012-05-06 05:47:55
【问题描述】:

我有一个相对简单的问题,即在继承到当前控件时调用 DataGridView.Rows.Add 函数的最佳方式。哪个是调用继承控件的最佳方式?直接在调用中调用它还是使用类递归函数调用它?它们似乎都产生相同的结果,添加一行并返回数量,但哪个效率最高?

委托人:Private Delegate Function ReturnDelegate() As Object

两种方式分别是:
一)

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

【问题讨论】:

    标签: vb.net datagridview invoke multithreading


    【解决方案1】:

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

    【讨论】:

    • 请记住,这些操作应该以事务格式编码:BeginUpdate(),使用 EndUpdate(true) 尝试块,使用 EndUpdate(false) 捕获块。
    • 我没有看到 DataGridView 或 Rows 控件的 BeginUpdate 和 EndUpdate -- 你能提供一个代码示例吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-13
    • 1970-01-01
    • 2013-04-23
    • 2015-11-16
    相关资源
    最近更新 更多