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

Shutdown issue #585

Closed
mohdimas opened this issue Nov 10, 2014 · 18 comments
Closed

Shutdown issue #585

mohdimas opened this issue Nov 10, 2014 · 18 comments
Milestone

Comments

@mohdimas
Copy link
Contributor

Hi guys,
I can't seems to call the Shutdown, I think this case is similar with this one #2.
So the problem is I can't close my app because when I called Shutdown the thread stuck there, and the app just continue running.

static void Shutdown()

@jornh
Copy link
Contributor

jornh commented Nov 11, 2014

I just found https://code.google.com/p/chromiumembedded/issues/detail?id=421 so if you are trying to implement #574 (comment) it looks unlikely it will work.

If you are just looking for a single shutdown at application exit have you made sure to dispose all ChromiumWebBrowser instances first (search the CefSharp WPF related code). #2 has a hint on some refcounting.

@mohdimas
Copy link
Contributor Author

No this one is just to shutdown when exiting the app. Ok thanks I'll try it and see how it turns out.

@amaitland
Copy link
Member

@myrnazhou Do you know what line it hands on? Does it enter into the lock?

@bjarteskogoy
Copy link

I had this problem on WPF + cef later than 1750. The problem was related to initlizing Cef on another thread than the Dispatcher. It got stuck when disposing.

@mohdimas
Copy link
Contributor Author

@bjarteskogoy
So did you manage to get the shutdown working?

@bjarteskogoy
Copy link

@myrnazhou Yes. Had to initialize it in the Dispatcher thread. Fixed it for me.

@mohdimas
Copy link
Contributor Author

I got this popup after I call the shutdown, I think it's related.
shutdown error

@Bodekaer
Copy link
Contributor

Bodekaer commented Jan 9, 2015

I see the same popup as @myrnazhou when closing the application, and running CEF Shutdown.
It's happening randomly, and hard to reproduce.

@myrnazhou did you try @jornh's suggestion to first dispose all browsers before calling shutdown?

@amaitland amaitland added this to the 39.0.0 milestone Jan 9, 2015
@amaitland
Copy link
Member

@Bodekaer
Copy link
Contributor

Bodekaer commented Jan 9, 2015

Update:
I tried the suggestion from #2 to dispose all browsers and call GC.Collect() and it appears to have solved it!
Thanks a lot for the tips.

I believe the main cause was that we sometimes store browsers in memory without displaying them (for faster re-load times when displaying new browsers).
I simply added a script to dispose all those browsers before calling Shutdown().

Wonderful! :) This was one that's been worrying me for a while, and yet it was so easy to fix :) hehe

@amaitland
Copy link
Member

@Bodekaer Excellent! Is it worth implementing the changes in CefSharp?

@Bodekaer
Copy link
Contributor

Bodekaer commented Jan 9, 2015

Yeah I guess it would. Although I'm not so happy with my implementation yet, so wouldn't feel too good about putting it into CefSharp :)
Anyways, here is the simple quick solution:

 public class ChromiumWebBrowser

     private static readonly List<WebControl> _instances = new List<ChromiumWebBrowser>();

     public ChromiumWebBrowser(){
           _instances.Add(this);
     }

    protected override void Dispose(bool isdisposing)
    {
        _instances.Remove(this);
        base.Dispose(isdisposing);
    }

    public static void DisposeAllInstances()
    {
        // Loop through all instances and remove.
        while (_instances.Count > 0)
        {
            _instances[0].Dispose();
        }
    }

}

And then I just call ChromiumWebBrowser.DisposeAllInstances() before calling Cef.Shutdown().
I'm sure this can be done 100x better, just haven't had time to look more into it yet.
:)

@amaitland
Copy link
Member

Interesting! I'm surprised that's nessicary. See
https://github.com/cefsharp/CefSharp/blob/cef/2171/CefSharp.Core/Cef.h#L330

Already does something very similar.

@Bodekaer
Copy link
Contributor

Haha yes that is strange :)
Well it seems like it doesn't call the Dispose() here, which may be the cause, as we have certain event handlers that are unsubscribed in the Disposing(bool isDisposing) method of our extended ChromiumWebBrowser.

Could that be the reason?

@amaitland
Copy link
Member

Well it seems like it doesn't call the Dispose() here, which may be the cause, as we have certain event handlers that are unsubscribed in the Disposing(bool isDisposing) method of our extended ChromiumWebBrowser

Quite possible, probably worth looking into 👍

@amaitland
Copy link
Member

@Bodekaer Happy to close this?

@Bodekaer
Copy link
Contributor

I actually just experienced this again yesterday.
It seems to still happen in very rare cases, but I think it's more related to cases where the JS execution somehow timed out, which seems to cause the dispose calls to freeze.

Let's close this issue though, as once I have a way to reproduce this other rare case, then I'll just open a new issue.
Since I've only experienced this new scenario once, it might also just be caused by something else and not be CefSharp related.

@amaitland
Copy link
Member

Let's close this issue though, as once I have a way to reproduce this other rare case, then I'll just open a new issue.

Works for me 😄

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

No branches or pull requests

5 participants