From efb841fdca0cbacb27df1fba413ae23ce6c90b91 Mon Sep 17 00:00:00 2001 From: amaitland Date: Thu, 8 Oct 2015 22:37:14 +1000 Subject: [PATCH] Add CefSharpSettings.ShutdownOnExit - all the user to disable the inbuilt call to Cef.Shutdown (Also needs to set shutdownOnProcessExit:false when calling Cef.Initialize, or the ParentProcessExitHandler will be called to Shutdown Cef) --- CefSharp.WinForms/ChromiumWebBrowser.cs | 5 ++++- CefSharp.Wpf/ChromiumWebBrowser.cs | 11 +++++++---- CefSharp/CefSharpSettings.cs | 16 ++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) 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; } } }