cefsharp - 使用两个 cefsharp.winforms 实例关闭时,对象引用未设置为对象的实例
问题描述
我的 wpf 使用了两个 ChromiumWebBrowser(Cefsharp.Winforms) 实例,一个用于我的网站,一个用于显示 pdf 文件,当我关闭 MianWindow 时,会出现如下崩溃:
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=CefSharp.WinForms
StackTrace:
在 CefSharp.WinForms.ChromiumWebBrowser.InternalDispose(Boolean disposing)
在 CefSharp.WinForms.ChromiumWebBrowser.Dispose(Boolean disposing)
在 System.ComponentModel.Component.Dispose()
在 System.Windows.Forms.Control.Dispose(Boolean disposing)
在 System.Windows.Forms.Integration.WinFormsAdapter.Dispose(Boolean disposing)
在 System.ComponentModel.Component.Dispose()
在 System.Windows.Forms.Integration.WindowsFormsHost.Dispose(Boolean disposing)
在 System.Windows.Interop.HwndHost.WeakEventDispatcherShutdown.OnShutdownFinished(Object sender, EventArgs e)
在 System.EventHandler.Invoke(Object sender, EventArgs e)
在 System.Windows.Threading.Dispatcher.ShutdownImplInSecurityContext(Object state)
在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Windows.Threading.Dispatcher.ShutdownImpl()
在 System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
在 System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
在 System.Windows.Application.RunDispatcher(Object ignore)
在 System.Windows.Application.RunInternal(Window window)
在 System.Windows.Application.Run(Window window)
在 System.Windows.Application.Run()
我没有明确设置 CefSharpSettings.ShutdownOnExit,在我的关闭函数中,只需调用:
Application.Current.Shutdown();
如果为pdf删除一个就可以了。我在下面托管浏览器:
<WindowsFormsHost Name="browserHost">
<cefwpf:ChromiumWebBrowser x:Name="browser" IsBrowserInitializedChanged="browser_IsBrowserInitializedChanged">
</cefwpf:ChromiumWebBrowser>
</WindowsFormsHost>
我的 cefsharp 版本是 83.1.100 感谢您的帮助!
解决方案
推荐阅读
- c# - 用于删除 Xamarin.Forms 中当前 ListView 行的按钮
- regex - 连接黑名单以在 CSV 文件中用作 AWK gsub 正则表达式
- rust - 如何在方法中获取对结构字段的可变引用并调用其他方法而不会引起借用检查器的抱怨?
- python - 使用 Python,生成 100 X 100 随机矩阵,其条目是从正态分布中采样的
- python-3.x - 无法在 Jupyter Notebook 上生成交互式绘图
- android - Android应用程序中的致命异常,但没有堆栈跟踪
- python - 如何使用自定义编解码器将 numpy 数组保存为字节?
- django - 在 django 模板多列中创建表格行字段
- laravel - 使用 laravel Http 门面的 poloniex 上的无效命令错误
- mobile - A-frame 屏幕空间反射