vb.net - 为什么我的调用会使网格加载时间增加 10 秒?

标签 vb.net datasource backgroundworker invoke radgridview

我尝试添加一个方法调用程序来阻止我的错误日志被垃圾邮件“锁定时无法更改边界。”

这解决了我的问题,但是...它使我的 RadGridView 的加载时间额外增加了 10 秒。

我查看了https://www.telerik.com/forums/bounds-cannot-be-changed-while-locked设置我的调用程序,但我看不到太多其他内容可以帮助解决我的问题。

我在下面附上了我的代码示例,如有任何帮助,我们将不胜感激。

Private Sub bgw_initialLoad_DoWork(sender As Object, e As DoWorkEventArgs)
        Try
            liveDS = New DataSet
            Dim dsholder As DataSet = GetDataFromSQL("LoadData")

            Dim dt1 As DataTable = dsholder.Tables(0)
            Dim dt_1 As DataTable = dt1.Copy()
            dt_1.TableName = "Customer"
            liveDS.Tables.Add(dt_1)

            Dim dt2 As DataTable = dsholder.Tables(1)
            Dim dt_2 As DataTable = dt2.Copy()
            dt_2.TableName = "Orders"
            liveDS.Tables.Add(dt_2)

            Dim dt3 As DataTable = dsholder.Tables(2)
            Dim dt_3 As DataTable = dt3.Copy()
            dt_3.TableName = "OrderLine"
            liveDS.Tables.Add(dt_3)

            If RadGridView.InvokeRequired Then
                RadGridView.Invoke(New MethodInvoker(AddressOf SetupDataSources))
            Else
                SetupDataSources()
            End If
        Catch ex As Exception
            sendCaughtError(ex)
        End Try
    End Sub

    Private Sub SetupDataSources()
        If liveDS.Tables.Count > 1 Then
            RadGridView.DataSource = liveDS.Tables("Customer")
            liveOrdersTemplate.DataSource = liveDS.Tables("Orders")
            liveOrdersTemplate2.DataSource = liveDS.Tables("OrderLine")
        End If
    End Sub

    Private Sub bgw_initialLoad_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs)
            Try
                RadGridView.DataSource = liveDS.Tables("Customer")
    
                Dim template As New GridViewTemplate()
                template.DataSource = liveDS.Tables("Orders")
                RadGridView.MasterTemplate.Templates.Add(template)
    
                Dim template2 As New GridViewTemplate()
                template2.DataSource = liveDS.Tables("OrderLine")
                RadGridView.Templates(0).Templates.Add(template2)
    
                Dim relation As New GridViewRelation(RadGridView.MasterTemplate)
                relation.ChildTemplate = template
                relation.ParentColumnNames.Add("Invoice Customer")
                relation.ChildColumnNames.Add("InvoiceCode")
                RadGridView.Relations.Add(relation)
    
                Dim relation2 As New GridViewRelation(RadGridView.Templates(0))
                relation2.ChildTemplate = template2
                relation2.ParentColumnNames.Add("OrderNo")
                relation2.ChildColumnNames.Add("OrderNo")
                RadGridView.Relations.Add(relation2)
    
                FormatGrid()
                SplitContainer2.Panel1.Enabled = True
                SplitContainer1.Panel2.Enabled = True
                refreshMainGrid()
                HideLoadingGif()
            Catch ex As Exception
                sendCaughtError(ex)
            End Try
        End Sub

最佳答案

调试线程可能很困难,相信我。这不是一个“真正的”答案,而是一些可能有帮助的提示 - 这就是我希望发生的事情。

调试菜单中有专用窗口可能会有所帮助。我从 this webpage 开始当我想知道我的应用程序发生了什么以及为什么发生这种情况并不明显时。

此外,当您的并行线程正在运行时,如果您的 IDE 未设置为每次崩溃时暂停,它可能会“无声崩溃”,在这种情况下,它不会返回值,而只会保持沉默。确保至少设置了以下选项:

Break on crash

Parallel stacks order

并且不要忘记在调试时显示此窗口:(上一张图片显示了线程和调用堆栈,虽然在调试时它们很好用,但我想要的是并行堆栈 )

Parallel stacks

最后一件事:这么大的延迟可能与数据库有关。我并不是说确实如此,但您应该意识到这种可能性。

现在,以下内容本身并不是答案的一部分,而是更多的友好建议:将您的调用逻辑放在 SetupDataSources() 中,这样无论它被调用,您都会在线程安全。像这样:

Private Sub SetupDataSources()
    If RadGridView.InvokeRequired Then
        RadGridView.Invoke(Sub() SetupDataSources())
    End If

    If liveDS.Tables.Count > 1 Then
        RadGridView.DataSource = liveDS.Tables("Customer")
        liveOrdersTemplate.DataSource = liveDS.Tables("Orders")
        liveOrdersTemplate2.DataSource = liveDS.Tables("OrderLine")
    End If
End Sub

祝你好运...你可能需要一些;)

关于vb.net - 为什么我的调用会使网格加载时间增加 10 秒?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63268304/

相关文章:

vb.net - 日期。现在不显示 12 小时格式

SQL - 添加/禁用基于 Select 语句中的 bool 条件的 Where 子句 (ASP.net SQLDataSource)

c# - RunWorkerCompleted 未在主 UI 线程中执行?

c# - .NET 4.0 TPL 不是让 APM、EAP 和 BackgroundWorker 异步模式过时了吗?

java - Android 应用程序仍然保持 Activity 状态,没有任何 Activity

c# - WinForms UserControl 如何停止控件接收焦点

从 vb 应用程序插入的 mysql (phpmyadmin) 行没有得到更新

ios - 使用文件作为 UITableView 的数据源

java - Spring Boot : How to Disable JNDI lookup and use spring. 数据源代替测试?

grails - 在 JDBC 设置之后尝试启动 Grails 时出错