views:

45

answers:

1

I'm working with the DevExpress XtraGrid control.

I have a routine that goes thru and adds all the controls on the current form dynamically, and launches on a seperate thread the routine for a given control to initialize it to the value that will be displayed to the end-user. Some of the controls are displaying calculated values, and take some time to return their values, so that's why we are doing it on a seperate thread.

Everything is working as expected EXCEPT the DevExpress XtraGrid control in a specific situation.

    Private Delegate Sub SetGridDataSourceDelegate(ByVal Data As List(Of myItem))

    Private Sub SetGridDataSource(ByVal Data As List(Of myItem))
        If Not IsNothing(myItemGrid) Then
            If myItemGrid.InvokeRequired Then
                Dim d As New SetGridDataSourceDelegate(AddressOf SetGridDataSource)
                myItemGrid.Invoke(d, New Object() {Data})
            Else
                myItemGrid.DataSource = Data
            End If
        End If
    End Sub

I'm using a similar snippet of code for any control properties that have to be updated, and all work fine. On the above code when the actual Invoke is called, it APPEARS that the thread just ends and never calls the delegate, and doesn't return to finish either.

Anyone have any thoughts on what might be causing this strange behavior?

+1  A: 

Hm... "And" what?

Change this:

If myItemGrid.InvokeRequired And Then

to:

If myItemGrid.InvokeRequired Then
Guffa