问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/45919551/cefsharp-browsersubprocess-are-not-closed-when-chromiumwebbrowser-is-disposed