mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-04 10:22:55 +00:00
130c3789f5
Follow up to #2375
70 lines
2.2 KiB
C#
70 lines
2.2 KiB
C#
// Copyright © 2010-2017 The CefSharp Authors. All rights reserved.
|
|
//
|
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
|
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.Threading.Tasks;
|
|
using CefSharp.Internals;
|
|
|
|
namespace CefSharp.BrowserSubprocess
|
|
{
|
|
public class Program
|
|
{
|
|
public static int Main(string[] args)
|
|
{
|
|
Debug.WriteLine("BrowserSubprocess starting up with command line: " + String.Join("\n", args));
|
|
|
|
SubProcess.EnableHighDPISupport();
|
|
|
|
int result;
|
|
var type = args.GetArgumentValue(CefSharpArguments.SubProcessTypeArgument);
|
|
var parentProcessId = int.Parse(args.GetArgumentValue(CefSharpArguments.HostProcessIdArgument));
|
|
if (args.HasArgument(CefSharpArguments.ExitIfParentProcessClosed))
|
|
{
|
|
Task.Factory.StartNew(() => AwaitParentProcessExit(parentProcessId), TaskCreationOptions.LongRunning);
|
|
}
|
|
|
|
//Use our custom subProcess provides features like EvaluateJavascript
|
|
if (type == "renderer")
|
|
{
|
|
var wcfEnabled = args.HasArgument(CefSharpArguments.WcfEnabledArgument);
|
|
var subProcess = wcfEnabled ? new WcfEnabledSubProcess(parentProcessId, args) : new SubProcess(args);
|
|
|
|
using (subProcess)
|
|
{
|
|
result = subProcess.Run();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
result = SubProcess.ExecuteProcess();
|
|
}
|
|
|
|
Debug.WriteLine("BrowserSubprocess shutting down.");
|
|
|
|
return result;
|
|
}
|
|
|
|
private static async void AwaitParentProcessExit(int parentProcessId)
|
|
{
|
|
try
|
|
{
|
|
var parentProcess = Process.GetProcessById(parentProcessId);
|
|
parentProcess.WaitForExit();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
//main process probably died already
|
|
Debug.WriteLine(e);
|
|
}
|
|
|
|
await Task.Delay(1000); //wait a bit before exiting
|
|
|
|
Debug.WriteLine("BrowserSubprocess shutting down forcibly.");
|
|
|
|
Environment.Exit(0);
|
|
}
|
|
}
|
|
}
|