CefSharp icon indicating copy to clipboard operation
CefSharp copied to clipboard

App slow to close when using RegisterJsObject in version >=43

Open MartySVK opened this issue 11 years ago • 35 comments

Hi, after upgrade cefsharp to 43 (winforms) and I have a problem with closing my program. It takes about 10 seconds. The problem is with RegisterJsObject. I have no idea, why it is happening, but when I delete the line with RegisterJsObject, everything is fine. It does not matter, if website contain function or not. After first load of website, the program has problem with closing.

But I can not reproduce this fault on your minimal example. Any idea where could be the problem?

chromeBrowser = new ChromiumWebBrowser(String.Empty);
chromeBrowser.RegisterJsObject("jscall", this, false);

MartySVK avatar Sep 29 '15 15:09 MartySVK

Hi, can you check my simple application ? https://github.com/MartySVK/TestCefSharpJS

MartySVK avatar Oct 06 '15 09:10 MartySVK

The sample I provided was for a close button handler, try removing your closing handler altogether. You may need to move your Initialize code into program main.

https://github.com/cefsharp/CefSharp.MinimalExample/blob/master/CefSharp.MinimalExample.WinForms/Program.cs#L15

I'm not near Visual Studio at the moment, so will test it later :+1:

amaitland avatar Oct 06 '15 11:10 amaitland

Removing the Dispose/Shutdown calls and letting the framework handle them seems to be working in your very simple demo.

https://github.com/amaitland/TestCefSharpJS/commit/e6adb8dddc2921fc121fbf2449ff52c927ff4db4

amaitland avatar Oct 08 '15 09:10 amaitland

Hi, when I remove Dispose/Shutdown, it is working, but is it safe to calling Initialize and not Shutdown ?

MartySVK avatar Oct 08 '15 12:10 MartySVK

it is working, but is it safe to calling Initialize and not Shutdown ?

CEF requires that you call Shutdown, and for that reason CefSharp will by default call Shutdown for you.

https://github.com/cefsharp/CefSharp/blob/master/CefSharp.WinForms/ChromiumWebBrowser.cs#L76 https://github.com/cefsharp/CefSharp/blob/master/CefSharp.Core/Cef.h#L208

amaitland avatar Oct 08 '15 12:10 amaitland

For most cases this is hopefully a functional workaround. At some stage someone will need to investigate the problem further.

amaitland avatar Oct 08 '15 12:10 amaitland

I've added the option to specify the Timeout to master

https://github.com/cefsharp/CefSharp/commit/d1ba723bd51c01a926a5fa6209de9358734f795e

Still just a workaround for the underlying problem.

amaitland avatar Oct 08 '15 12:10 amaitland

i add this before form.close(), works for me form.Controls.Remove(browser);

culmencasa avatar Mar 31 '16 08:03 culmencasa

I've just experienced the same problem with v49.0.1. @culmencasa 's Workaround with removing the control in my Form_Close handler fixes this issue.

kpko avatar Jun 01 '16 21:06 kpko

I've seen this issue appear in our project since release v49.

am able to workaround using below code in the formclose handler.

                CefSharpSettings.WcfTimeout = new TimeSpan(0);
                Browser.Dispose();
                Application.DoEvents();
                CefSharpSettings.WcfTimeout = new TimeSpan(0,0,0,10);

not sure if that is how the timeout what intended to be used.. What is Wcf used for, Communication with JS?

dandotevans avatar Jul 26 '16 12:07 dandotevans

@dandotevans Simple set WcfTimeout to Zero early on in your app would be sufficient. No need to reset.

What is Wcf used for, Communication with JS?

Javascript Binding uses WCF for communication. Switch to the async version and it will only use the native IPC (and is faster).

amaitland avatar Aug 02 '16 23:08 amaitland

Small hack (only winforms):

Browser.Parent.Dispose();
Cef.Shutdown();

vovanre avatar Dec 16 '16 18:12 vovanre

CefSharpSettings.WcfEnabled = false; Cef.Shutdown();

Jovan-Cheng avatar Jan 03 '17 02:01 Jovan-Cheng

CefSharpSettings.WcfEnabled = false;

Setting WcfEnabled to false before calling Shutdown may lead to an undesired result so beware. https://github.com/cefsharp/CefSharp/blob/11dee93bf331f012dd6416fb2f2162549d9137a3/CefSharp.Core/ManagedCefBrowserAdapter.h#L90

amaitland avatar Jan 03 '17 05:01 amaitland

Closing as I've not seen reports of this in quite some time. Anyone experiencing this problem should set

CefSharpSettings.WcfTimeout = new TimeSpan(0);

Before you create the first ChromiumWebBrowser instance. The WCF channel will be aborted and won't wait for close.

amaitland avatar May 02 '18 04:05 amaitland