处置ChromiumWebBrowser时未关闭CefSharp.BrowserSubprocess [英] CefSharp.BrowserSubprocess are not closed when ChromiumWebBrowser is Disposed
问题描述
我在WPF中使用CefSharp 55。每次我创建新的 ChromiumWebBrowser
时,任务管理器中都会出现一个新的CefSharp.BrowserSubprocess.exe,这很正常。但是当我在 ChromiumWebBrowser
上调用 Dispose()
时,它们并不会消失。它们仅在我关闭Apllication时消失,这可能是因为当时我调用 Cef.Shutdown()
。在处置后,我尝试强制使用GC,但我什么也没做。
因此,如果用户在网络浏览器中不断打开和关闭标签页,我们最终会得到很多CefSharp
在扩展 ChromiumWebBrowser
,我愿意
var requestContextSettings = new RequestContextSettings
{
PersistSessionCookies = false,
IgnoreCertificateErrors = true
};
RequestContext = new RequestContext(requestContextSettings);
在处置浏览器时,请
browser.Dispose();
browser.RequestContext.Dispose()
我忘了什么吗?
编辑
显然,该问题不仅限于CefSharp.BrowserSubprocess。当我放置浏览器播放youtube视频时,视频的声音仍在运行。之前工作正常,处置后视频声音被切断。也许这是我最近更新的新版本的CefSharp中的错误。
我发现了问题所在。我做了一个 ILifeSpanHandler
的实现,在其中我在 DoClose(...)
中返回了true,因为我虽然返回了true Mean您告诉浏览器可以关闭。但是在文档中说返回false会立即破坏浏览器。
( https://github.com/cefsharp/CefSharp/blob/master/CefSharp/Handler/ILifeSpanHandler.cs )
完成此操作后,CefSharp当我关闭相应的Web浏览器时,BrowserSubprocess关闭。
I am using CefSharp 55 in WPF. every time I make a new ChromiumWebBrowser
, a new CefSharp.BrowserSubprocess.exe appear in the task manager, which is normal. But they don't disappear when I call Dispose()
on a ChromiumWebBrowser
. They only disappear when I close the Apllication, propably because at that time I call Cef.Shutdown()
. I tried to Force GC after the dispose but i change nothing.
So if the user keep opening and closing tabs in the web browser, we end up with a lot of CefSharp.BrowserSubprocess running which will never be closed exept when the app is closed.
In the constructor of the class extending ChromiumWebBrowser
,I do
var requestContextSettings = new RequestContextSettings
{
PersistSessionCookies = false,
IgnoreCertificateErrors = true
};
RequestContext = new RequestContext(requestContextSettings);
When I dispose the browser, do
browser.Dispose();
browser.RequestContext.Dispose()
Did I forgot something?
Edit
Apparently it the problem is not limited to CefSharp.BrowserSubprocess. When I dispose a browser playing a youtube video, The sound of the video is still running. It was working before, the video sound was cut after the dispose. Maybe it is a bug in the new version of CefSharp that I updated recently.
I found what was the problem. I made an implementation of ILifeSpanHandler
where I was returning true in DoClose(...)
because I though returning true mean you tell the browser it can close. But in the doc it say to return false to destroy the browser immediatly.
(https://github.com/cefsharp/CefSharp/blob/master/CefSharp/Handler/ILifeSpanHandler.cs)
After doing this, The CefSharp.BrowserSubprocess are closed when I close the corresponding web browser.
这篇关于处置ChromiumWebBrowser时未关闭CefSharp.BrowserSubprocess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!