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

Adding a DocumentWindow to a DocumentTabStrip causes the application to hang indefinitely

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

我最近将网络浏览器控件从基于 IE 的内置 .NET 网络浏览器切换到 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

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

从未抛出任何异常,因为您患有 deadlock