2

I've attempted to add a method invoker to stop my error log being spammed with "Bounds cannot be changed while locked."

This has solved my issue, however...It has added an extra 10 seconds onto the loading time of my RadGridView.

I looked at https://www.telerik.com/forums/bounds-cannot-be-changed-while-locked to setup my invoker but there isn't much else that I can see to help with my issue.

I've attached a sample of my code below, any help would be appreciated.

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
Oliver
  • 161
  • 2
  • 9

1 Answers1

3

Debugging threads can be hard, trust me. This isn't a "real" answer, but a bunch of tips which may help - which is what I hope will happen.

There are dedicated windows in the debug menu which may help. I started with this webpage when I was wondering what was happening to my application and why it wasn't obvious why it was happening.

Also, while your parallel thread is running, it may "silent crash" if your IDE isn't set to pause on every crash, in which case it won't return a value but will just stay silent. Make sure at least these options are set:

Break on crash

Parallel stacks order

And don't forget to show this window while debugging: (previous image showed Threads and Call stack instead, while they are good to have around while debugging it's the parallel stacks which I was going for)

Parallel stacks

One last thing: such a big delay may be database related. I'm not saying that it is, but you should be aware of the possibility.

Now the following isn't part of the answer per se, but is more of a friendly advice: put your invoke logic in SetupDataSources() instead, this way wherever it's called you'll be thread safe. Like this:

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

Best of luck... you might need some ;)

laancelot
  • 3,138
  • 2
  • 14
  • 21
  • 1
    If working with multiple threads, the "Parallel Stacks" window is potentially more useful than the "Call Stack" window. – Craig Aug 05 '20 at 18:14
  • @Craig Indeed, I somehow mixed Threads and Parallel stacks. I'm updating this. – laancelot Aug 05 '20 at 18:37
  • @laancelot thanks! I've implemented the suggestions, however when debugging nothing is appearing in the parallel stacks window, I've moved the invoke to the SetupDataSources method but now it's not being called - does this mean I'm unnecessarily assigning the data sources twice as the data still loads when I click my refresh button – Oliver Aug 06 '20 at 08:21
  • @Oliver Like a Watch, the Parallel Stacks won't be usable unless you're in a breakpoint. You should have AT LEAST one thread, even without multithreading. – laancelot Aug 06 '20 at 16:15