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



我有一个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

我假设InvokeIfRequired是您为Control创建的扩展方法。 请注意,如果它依赖于Invoke,那就是同步调用,则使用BeginInvoke(请参阅:Invoke((和BeginInvoke((有什么区别(

从来没有因为您遭受死锁而抛出任何例外

最新更新