wpf 处置 ChromiumWebBrowser 时,CefSharp.BrowserSubprocess 不会关闭

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45919551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 14:08:21  来源:igfitidea点击:

CefSharp.BrowserSubprocess are not closed when ChromiumWebBrowser is Disposed

c#wpfcefsharp

提问by Gael

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.

我在 WPF 中使用 CefSharp 55。每次新建ChromiumWebBrowser一个,任务管理器中都会出现一个新的CefSharp.BrowserSubprocess.exe,这是正常的。但是,他们当我打电话不会消失Dispose()ChromiumWebBrowser。它们只有在我关闭应用程序时才会消失,可能是因为当时我打电话给Cef.Shutdown(). 我试图在处理后强制 GC,但我什么也没改变。

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.

因此,如果用户在 Web 浏览器中不断打开和关闭选项卡,我们最终会运行很多 CefSharp.BrowserSubprocess,它们永远不会在应用程序关闭时关闭。

In the constructor of the class extending ChromiumWebBrowser,I do

在扩展类的构造函数中ChromiumWebBrowser,我做

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.

显然,问题不仅限于 CefSharp.BrowserSubprocess。当我处理播放 youtube 视频的浏览器时,视频的声音仍在运行。之前是正常的,处理后视频声音被剪掉了。可能是我最近更新的新版 CefSharp 的一个 bug。

回答by Gael

I found what was the problem. I made an implementation of ILifeSpanHandlerwhere 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.

我发现了问题所在。我实现了ILifeSpanHandler我返回 true 的位置,DoClose(...)因为我虽然返回 true 意味着你告诉浏览器它可以关闭。但是在文档中它说返回 false 以立即销毁浏览器。

(https://github.com/cefsharp/CefSharp/blob/master/CefSharp/Handler/ILifeSpanHandler.cs)

( 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.

执行此操作后,当我关闭相应的 Web 浏览器时,CefSharp.BrowserSubprocess 将关闭。