0

I have a Winforms application with a primary form that contains (among other things) a Telerik DocumentTabStrip. These tabs are used to hold user controls or web pages (via a web browser control). It has worked fine for quite a while, but I'm running into an issue now.

I recently switched the web browser control from the built-in .NET web browser based on IE to CefSharp. Since doing so, I've noticed that occasionally when trying to add the DocumentWindow to the DocumentTabStrip, the call will hang indefinitely (in debug) or crash outright (running the app normally). This only appears to happen when opening a DocumentWindow that contains the browser control, not any other user controls. The actual call itself is below.

I'm at a bit of a loss as to how to even begin to debug this, since there's no error that gets received - it just hangs inside the Controls.Add() method indefinitely. Any advice would be appreciated.

Private dts As New Telerik.WinControls.UI.Docking.DocumentTabStrip


Try


    dts.InvokeIfRequired(Sub()
        Dim docWindow As Telerik.WinControls.UI.Docking.DocumentWindow = Nothing
        Dim ctrl As ucBaseControl = Nothing
        Dim browser As ucBrowser = Nothing
        Dim isBrowser As Boolean = False

        docWindow = New Telerik.WinControls.UI.Docking.DocumentWindow
        docWindow.BackColor = Color.FromArgb(89, 89, 89)

        'Do various stuff to determine the type of control to load (ctrl or browser), then setup the applicable control

        If isBrowser Then
            'Place the browser into the Document Window.
            If Not IsNothing(browser) Then
                browser.Dock = DockStyle.Fill
                docWindow.Controls.Add(browser)
            End If
        Else
            'Place the ctrl into the Document Window.
            ctrl.Dock = DockStyle.Fill
            docWindow.Controls.Add(ctrl)
        End If

        'Add the DocumentWindow to the DocumentTabStrip
        ' Ensure DockWindow not disposed due to lag in bringing up
        If IsNothing(docWindow) OrElse docWindow.IsDisposed Then
            Exit Sub
        End If
        Try
            docWindow.Padding = New Padding(0)
            dts.TabStripElement.Children(0).Children(1).Padding = New Padding(0)
            dts.Controls.Add(docWindow)  'This is where the issue is. It only happens sporadically here.
        Catch ex As Exception
            'Code to log any exceptions here. In the problem described here, no exception is ever generated, though.
        End Try

        'Bring the control to the front and focus it, here...
    End Sub)
Catch ex As Exception
    'Error handling code here'
End Try
Michael
  • 1,036
  • 1
  • 11
  • 22
  • Is any exception being thrown? If so, post the stack trace. – TEK Mar 18 '17 at 22:09
  • @TEK Nope, no exception at all. When stepping through, it just goes into the Controls.Add method and never returns. Outside of Visual Studio, it goes to add the DocumentWindow and crashes without any errors. – Michael Mar 19 '17 at 03:35
  • What is the logic of your `InvokeIfRequired` method? I'm assuming it's an extension method you've created for `Control`s. Note that if it relies on `Invoke`, that is a synchronous call, instead use `BeginInvoke`(see: http://stackoverflow.com/questions/229554/whats-the-difference-between-invoke-and-begininvoke/229558#229558). Another starting point can be to try calling `dts.CreateControl()` after you call `dts.Controls.Add(docWindow)`. Note, these are just some debugging steps for you to work with, hence a comment and not an answer. – TEK Mar 19 '17 at 13:08
  • Just to add, it sounds as though you are suffering from deadlock. – TEK Mar 19 '17 at 13:24
  • If it's a hard crash then there should be an event viewer entry and/or a crash dump – amaitland Mar 20 '17 at 03:54
  • @TEK Turned out you were right. I just needed to change the Invoke to BeginInvoke. I'm still not sure why no exception was ever thrown, but if you want to create an answer I'll mark it. – Michael Mar 24 '17 at 03:07
  • @Locke Done. :-) – TEK Mar 24 '17 at 09:50

1 Answers1

1

I'm assuming InvokeIfRequired is an extension method you've created for Controls. Note that if it relies on Invoke, that is a synchronous call, instead use BeginInvoke (see: What's the difference between Invoke() and BeginInvoke())

No exception was ever thrown because you were suffering from deadlock

Community
  • 1
  • 1
TEK
  • 1,265
  • 1
  • 15
  • 30