Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Winform unload #147

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

madaster97
Copy link

In the WinForms minimal example, I noticed an issue where the "onunload" event doesn't seem to be firing if you click File > Exit. I think this is related to CefSharp issue #1574, where there's a bit of a race condition when you call browser.Dispose() before removing the browser from the holding control.

In my case, the website I'm trying to embed relies on the onunload event to fire an Ajax/fetch request that logs the user out. With the current example setup, the event is firing but (almost) every time the browser is torn down before the Ajax can send. I can even see the TCP/TLS connection for my Ajax call start (in Fiddler) but then don't see the request body sent out.

If I update the example to remove the browser from the control before Disposing the browser, I consistently see my calls complete!

toolStripContainer.ContentPanel.Controls.Remove(browser);

I think it would make sense to add this to the minimal example to show others a simple way to handle this, with a comment referencing the issue above. There are more complicated ways to handle this like implementing ILifespanHandler.DoClose. That and more already seems to be covered in the larger WinForms example.

// Prevent a race condition where browser.Dispose tears down it's control
// (before all browser cleanup has finished)
// https://github.com/cefsharp/CefSharp/issues/1574
// There are better/more complicated ways to handle this too
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be demonstrating one of those instead?

It's should now be a simple one liner, either of the following should work:

browser.LifeSpanHandler = new CefSharp.WinForms.Handler.LifeSpanHandler();

browser.LifeSpanHandler = CefSharp.WinForms.Handler.LifeSpanHandler
    .Create()
    .Build();

@madaster97
Copy link
Author

Thanks @amaitland , I will test this and get back soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants