diff --git a/CefSharp.WinForms/ChromiumWebBrowser.cs b/CefSharp.WinForms/ChromiumWebBrowser.cs index c0a8016d2..0be420f44 100644 --- a/CefSharp.WinForms/ChromiumWebBrowser.cs +++ b/CefSharp.WinForms/ChromiumWebBrowser.cs @@ -68,7 +68,10 @@ namespace CefSharp.WinForms static ChromiumWebBrowser() { - Application.ApplicationExit += OnApplicationExit; + if (CefSharpSettings.ShutdownOnExit) + { + Application.ApplicationExit += OnApplicationExit; + } } private static void OnApplicationExit(object sender, EventArgs e) diff --git a/CefSharp.Wpf/ChromiumWebBrowser.cs b/CefSharp.Wpf/ChromiumWebBrowser.cs index 06e516ddf..d65434a7a 100644 --- a/CefSharp.Wpf/ChromiumWebBrowser.cs +++ b/CefSharp.Wpf/ChromiumWebBrowser.cs @@ -84,11 +84,14 @@ namespace CefSharp.Wpf static ChromiumWebBrowser() { - var app = Application.Current; - - if (app != null) + if (CefSharpSettings.ShutdownOnExit) { - app.Exit += OnApplicationExit; + var app = Application.Current; + + if (app != null) + { + app.Exit += OnApplicationExit; + } } } diff --git a/CefSharp/CefSharpSettings.cs b/CefSharp/CefSharpSettings.cs index fd1b471c9..e9dc9d340 100644 --- a/CefSharp/CefSharpSettings.cs +++ b/CefSharp/CefSharpSettings.cs @@ -6,11 +6,27 @@ namespace CefSharp { public static class CefSharpSettings { + /// + /// Set default values for CefSharpSettings + /// + static CefSharpSettings() + { + ShutdownOnExit = true; + } + /// /// WCF is used by JavascriptBinding /// Disabling effectively disables both of these features. /// Defaults to true /// public static bool WcfEnabled { get; set; } + + /// + /// For the WinForms and WPF instances of ChromiumWebBrowser the relevant Application Exit event + /// is hooked and Cef.Shutdown() called by default. Set this to false to disable this behaviour. + /// This value needs to be set before the first instance of ChromiumWebBrowser is created as + /// the event handlers are hooked in the static constructor for the ChromiumWebBrowser class + /// + public static bool ShutdownOnExit { get; set; } } }