-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Close CefSharp.BrowserSubprocess.exe if parent process exits #2375
Close CefSharp.BrowserSubprocess.exe if parent process exits #2375
Conversation
✅ Build CefSharp 65.0.0-CI2580 completed (commit 04a14ebca8 by @joaompneves) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments inline
const string typePrefix = "--type="; | ||
var typeArgument = args.SingleOrDefault(arg => arg.StartsWith(typePrefix)); | ||
var type = typeArgument.Substring(typePrefix.Length); | ||
Task.Run(() => AwaitParentProcessExit(parentProcessId)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whilst the ThreadPool
won't be used in the render process, it just doesn't seem appropriate to use a vanilla Task.Run
, should probably add TaskCreationOptions.LongRunning
, from memory it should spawn a new Thread
and a quick check on stackoverflow
suggests it will.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I though about adding that, but since this process is running mostly unmanaged code and is not using the ThreadPool, I skipped it. But its a small change, I will do it.
{ | ||
//main process probably died already, bailout | ||
Debug.WriteLine(e); | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of this return?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed that the process would die by it self, but I'll remove it... its safer.
|
||
Task.Delay(1000); //wait a bit before exiting | ||
|
||
Debug.WriteLine("BrowserSubprocess shutting down forcibly."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably log to the native CEF Logging
, trivial to add an wrapper method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just copied the same pattern that was already there.
@@ -119,13 +119,12 @@ public CefCustomScheme() | |||
/// <returns>list of scheme objects</returns> | |||
public static List<CefCustomScheme> ParseCommandLineArguments(IEnumerable<string> args) | |||
{ | |||
var schemes = args.FirstOrDefault(a => a.StartsWith(CefSharpArguments.CustomSchemeArgument)); | |||
var schemes = args.GetArgumentValue(CefSharpArguments.CustomSchemeArgument); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you tested these changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes... and I even spotted an existing "bug". Some of the parameters sent to the process are duplicated, that's why the FirstOrDefault works but not not SIngleOrDefault.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which paramaters are duplicated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those defined in CefSharpArguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, thanks
✅ Build CefSharp 65.0.0-CI2591 completed (commit 352ba2bbda by @joaompneves) |
✅ Build CefSharp 65.0.0-CI2592 completed (commit 945f2381b4 by @joaompneves) |
Improve command line parsing Partial import of changes from #2375
Improve command line parsing Partial import of changes from #2375
I don't have time to properly review this before the I've manually cherry picked some pieces that are included in commit f2fcbf0 The process id will always be passed through and I've updated the command line parsing. This should give anyone wishing to try this feature out the ability to create their own When it comes time to merge this I'll resolve the conflicts. |
const string typePrefix = "--type="; | ||
var typeArgument = args.SingleOrDefault(arg => arg.StartsWith(typePrefix)); | ||
var type = typeArgument.Substring(typePrefix.Length); | ||
Task.Factory.StartNew(() => AwaitParentProcessExit(parentProcessId), TaskCreationOptions.LongRunning); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does not take a thread
var parentProcess = Process.GetProcessById(parentProcessId)
if(parentProcess != null)
{
parentProcess.EnableRaisingEvents = true;
parentProcess.Exited += (o,a) =>
{
Debug.WriteLine("BrowserSubprocess shutting down forcibly.");
Environment.Exit(0);
}
}
Debug.WriteLine(e); | ||
} | ||
|
||
Task.Delay(1000); //wait a bit before exiting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await Task.Delay(1000);
✅ Build CefSharp 66.0.0-CI2630 completed (commit c9683e79f9 by @joaompneves) |
❌ Build CefSharp 66.0.0-CI2631 failed (commit a29c000042 by @joaompneves) |
✅ Build CefSharp 66.0.0-CI2632 completed (commit 4af076c88c by @joaompneves) |
…k to monitor parent if command line arg present Follow up to #2375
* Close cefsharp subprocess if main process dies * Code review * Await before exiting * Update Program.cs
…k to monitor parent if command line arg present Follow up to #2375
Following the issue #2359 here is the "solution".
I tested this solution making the following changes in CefSharp.Wpf.Example\Views\BrowserTabView.xaml.cs: