diff --git a/CefSharp.BrowserSubprocess/Program.cs b/CefSharp.BrowserSubprocess/Program.cs
index 25773810c..3cac1d2bd 100644
--- a/CefSharp.BrowserSubprocess/Program.cs
+++ b/CefSharp.BrowserSubprocess/Program.cs
@@ -20,7 +20,10 @@ namespace CefSharp.BrowserSubprocess
int result;
var type = args.GetArgumentValue(CefSharpArguments.SubProcessTypeArgument);
var parentProcessId = int.Parse(args.GetArgumentValue(CefSharpArguments.HostProcessIdArgument));
- Task.Factory.StartNew(() => AwaitParentProcessExit(parentProcessId), TaskCreationOptions.LongRunning);
+ if (args.HasArgument(CefSharpArguments.ExitIfParentProcessClosed))
+ {
+ Task.Factory.StartNew(() => AwaitParentProcessExit(parentProcessId), TaskCreationOptions.LongRunning);
+ }
//Use our custom subProcess provides features like EvaluateJavascript
if (type == "renderer")
diff --git a/CefSharp.Core/Internals/CefSharpApp.h b/CefSharp.Core/Internals/CefSharpApp.h
index beb9c01a1..9f2cb6980 100644
--- a/CefSharp.Core/Internals/CefSharpApp.h
+++ b/CefSharp.Core/Internals/CefSharpApp.h
@@ -60,6 +60,11 @@ namespace CefSharp
commandLine->AppendArgument(StringUtils::ToNative(CefSharpArguments::WcfEnabledArgument));
}
+ if (CefSharpSettings::SubprocessExitIfParentProcessClosed)
+ {
+ commandLine->AppendSwitch(StringUtils::ToNative(CefSharpArguments::ExitIfParentProcessClosed));
+ }
+
//ChannelId was removed in https://bitbucket.org/chromiumembedded/cef/issues/1912/notreached-in-logchannelidandcookiestores
//We need to know the process Id to establish WCF communication and for monitoring of parent process exit
commandLine->AppendArgument(StringUtils::ToNative(CefSharpArguments::HostProcessIdArgument + "=" + Process::GetCurrentProcess()->Id));
diff --git a/CefSharp.Example/CefExample.cs b/CefSharp.Example/CefExample.cs
index c11628fb2..c7b820d2a 100644
--- a/CefSharp.Example/CefExample.cs
+++ b/CefSharp.Example/CefExample.cs
@@ -181,6 +181,18 @@ namespace CefSharp.Example
settings.FocusedNodeChangedEnabled = true;
+ //Experimental option where bound async methods are queued on TaskScheduler.Default.
+ //CefSharpSettings.ConcurrentTaskExecution = true;
+
+ //Legacy Binding Behaviour doesn't work for cross-site navigation (navigating to a different domain)
+ //See issue https://github.com/cefsharp/CefSharp/issues/1203 for details
+ //CefSharpSettings.LegacyJavascriptBindingEnabled = true;
+
+ //Exit the subprocess if the parent process happens to close
+ //This is optional at the moment
+ //https://github.com/cefsharp/CefSharp/pull/2375/
+ CefSharpSettings.SubprocessExitIfParentProcessClosed = true;
+
//NOTE: Set this before any calls to Cef.Initialize to specify a proxy with username and password
//One set this cannot be changed at runtime. If you need to change the proxy at runtime (dynamically) then
//see https://github.com/cefsharp/CefSharp/wiki/General-Usage#proxy-resolution
@@ -192,13 +204,6 @@ namespace CefSharp.Example
}
Cef.AddCrossOriginWhitelistEntry(BaseUrl, "https", "cefsharp.com", false);
-
- //Experimental option where bound async methods are queued on TaskScheduler.Default.
- //CefSharpSettings.ConcurrentTaskExecution = true;
-
- //Legacy Binding Behaviour doesn't work for cross-site navigation (navigating to a different domain)
- //See issue https://github.com/cefsharp/CefSharp/issues/1203 for details
- //CefSharpSettings.LegacyJavascriptBindingEnabled = true;
}
public static async void RegisterTestResources(IWebBrowser browser)
diff --git a/CefSharp/CefSharpSettings.cs b/CefSharp/CefSharpSettings.cs
index 5601b7371..bf1aa710c 100644
--- a/CefSharp/CefSharpSettings.cs
+++ b/CefSharp/CefSharpSettings.cs
@@ -70,6 +70,13 @@ namespace CefSharp
///
public static bool ShutdownOnExit { get; set; }
+ ///
+ /// CefSharp.BrowserSubprocess will monitor the parent process and exit if the parent process closes
+ /// before the subprocess. This currently defaults to false.
+ /// See https://github.com/cefsharp/CefSharp/issues/2359 for more information.
+ ///
+ public static bool SubprocessExitIfParentProcessClosed { get; set; }
+
///
/// The proxy options that will be used for all connections
///
diff --git a/CefSharp/Internals/CefSharpArguments.cs b/CefSharp/Internals/CefSharpArguments.cs
index 202020292..93d7ac490 100644
--- a/CefSharp/Internals/CefSharpArguments.cs
+++ b/CefSharp/Internals/CefSharpArguments.cs
@@ -11,5 +11,6 @@ namespace CefSharp.Internals
public const string CustomSchemeArgument = "--custom-scheme";
public const string FocusedNodeChangedEnabledArgument = "--focused-node-enabled";
public const string SubProcessTypeArgument = "--type";
+ public const string ExitIfParentProcessClosed = "--CefSharpExitSub";
}
}