簡體   English   中英

退出時未處理的異常

[英]Unhandled exception on exit

我正在嘗試在XAML / WPF應用程序中評估CefSharp是否對我們有用

當前,我們正在與MS的WebBrowser一起使用,但它存在嚴重的局限性。

我們的應用程序中有一個窗口,其中顯示幾個自定義控件之一,其中一個包含一個瀏覽器控件,該控件加載包含地圖的網頁。

為了進行測試,我創建了一個自定義控件,其中包含一個硬編碼為http://www.google.com的WebBrowser。

然后,我創建了第二個自定義控件,其中包含一個硬編碼為http://www.google.com的ChromiumWebBrowser。

我對代碼中的任何一個瀏覽器控件都不做任何事情,只是使包裹它們的用戶控件可見或折疊。

但是,如果我將Xrom中包含的ChromiumWebBrowser包含在內,無論是否使其可見,在退出時都會出現異常:

System.InvalidOperationException was unhandled
Message: An unhandled exception of type 'System.InvalidOperationException' occurred in WindowsBase.dll
Additional information: The calling thread cannot access this object because a different thread owns it.

為了明確起見,如果我的自定義控件包含此內容,則不會出現異常:

<KtWpf:KorUserControl 
        x:Class="KtWpf.CEFSharpUtilityMap"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:KtWpf="clr-namespace:KtWpf" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"
        >
    <DockPanel>
        <TextBox DockPanel.Dock="Top">CEFSharp</TextBox>
        <WebBrowser
                x:Name="mapBrowser"
                Source="http://www.google.com"
                />
    </DockPanel>
</KtWpf:KorUserControl>

如果包含此內容,我將執行以下操作:

<KtWpf:KorUserControl 
        x:Class="KtWpf.CEFSharpUtilityMap"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
        xmlns:KtWpf="clr-namespace:KtWpf" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"
        >
    <DockPanel>
        <TextBox DockPanel.Dock="Top">CEFSharp</TextBox>
        <cefSharp:ChromiumWebBrowser 
                x:Name="mapBrowser" 
                Address="http://www.google.com"
            />
    </DockPanel>
</KtWpf:KorUserControl>

有任何想法嗎?

我正在使用NuGet的CefSharp.Wfp版本49.0.0。 (還有CefSharp.Common和cef.redist.x64,盡管我為x86構建了相同的東西。)

===添加調用棧===

>   WindowsBase.dll!System.Windows.Threading.Dispatcher.VerifyAccess()  Unknown
PresentationCore.dll!MS.Internal.Media.VisualTreeUtils.AsVisual(System.Windows.DependencyObject element, out System.Windows.Media.Visual visual, out System.Windows.Media.Media3D.Visual3D visual3D)    Unknown
PresentationCore.dll!MS.Internal.Media.VisualTreeUtils.AsNonNullVisual(System.Windows.DependencyObject element, out System.Windows.Media.Visual visual, out System.Windows.Media.Media3D.Visual3D visual3D) Unknown
PresentationCore.dll!System.Windows.Media.VisualTreeHelper.GetParent(System.Windows.DependencyObject reference) Unknown
PresentationCore.dll!System.Windows.Media.Visual.ClearTreeBits(System.Windows.DependencyObject e, System.Windows.Media.VisualFlags treeFlag, System.Windows.Media.VisualFlags nodeFlag) Unknown
PresentationCore.dll!System.Windows.Media.Visual.VisualAncestorChanged.remove(System.Windows.Media.Visual.AncestorChangedEventHandler value)    Unknown
PresentationCore.dll!System.Windows.PresentationSource.RemoveSourceChangedHandler(System.Windows.IInputElement e, System.Windows.SourceChangedEventHandler handler) Unknown
CefSharp.Wpf.dll!CefSharp.Wpf.ChromiumWebBrowser.Dispose(bool isdisposing)  Unknown
CefSharp.Wpf.dll!CefSharp.Wpf.ChromiumWebBrowser.Dispose()  Unknown
CefSharp.Core.dll!CefSharp.Cef.Shutdown()   Unknown
CefSharp.Core.dll!CefSharp.Cef.ParentProcessExitHandler(object sender, System.EventArgs e)  Unknown

我們需要做的是控制初始化和關閉。

在App.OnStartup()中:

protected override void OnStartup(StartupEventArgs e)
{
    base.OnStartup(e);
    Cef.Initialize();
    ...
}

在App.OnExit()中:

protected override void OnExit(ExitEventArgs e)
{
    Cef.Shutdown();
    base.OnExit(e);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM