将DocumentWindow添加到DocumentTabStrip会导致应用程序无限期挂起

时间:2017-03-17 13:50:13

标签: winforms telerik cefsharp

我有一个Winforms应用程序,其主要表单包含(除其他外)Telerik DocumentTabStrip。这些选项卡用于保存用户控件或网页(通过Web浏览器控件)。它已经工作了很长一段时间,但我现在遇到了一个问题。

我最近将Web浏览器控件从基于IE的内置.NET Web浏览器切换到CefSharp。由于这样做,我注意到偶尔尝试将DocumentWindow添加到DocumentTabStrip时,调用将无限期挂起(在调试中)或直接崩溃(正常运行应用程序)。打开包含浏览器控件的DocumentWindow时,只有出现,而不是任何其他用户控件。实际的通话本身如下。

我对如何开始调试这一点感到有些失落,因为没有收到任何错误 - 它只是无限期地挂在Controls.Add()方法中。任何建议将不胜感激。

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

1 个答案:

答案 0 :(得分:1)

我假设InvokeIfRequired是您为Control创建的扩展方法。请注意,如果它依赖于Invoke,这是同步调用,请使用BeginInvoke(请参阅:What's the difference between Invoke() and BeginInvoke()

因为你患有deadlock

而没有例外