44
55using System ;
66using System . Diagnostics ;
7- using System . Threading . Tasks ;
8- using CefSharp . Internals ;
97using CefSharp . RenderProcess ;
108
119namespace CefSharp . BrowserSubprocess
@@ -23,63 +21,15 @@ public static int Main(string[] args)
2321
2422 SubProcess . EnableHighDPISupport ( ) ;
2523
26- int result ;
27- var type = args . GetArgumentValue ( CefSharpArguments . SubProcessTypeArgument ) ;
24+ //Add your own custom implementation of IRenderProcessHandler here
25+ IRenderProcessHandler handler = null ;
2826
29- var parentProcessId = - 1 ;
30-
31- // The Crashpad Handler doesn't have any HostProcessIdArgument, so we must not try to
32- // parse it lest we want an ArgumentNullException.
33- if ( type != "crashpad-handler" )
34- {
35- parentProcessId = int . Parse ( args . GetArgumentValue ( CefSharpArguments . HostProcessIdArgument ) ) ;
36- if ( args . HasArgument ( CefSharpArguments . ExitIfParentProcessClosed ) )
37- {
38- Task . Factory . StartNew ( ( ) => AwaitParentProcessExit ( parentProcessId ) , TaskCreationOptions . LongRunning ) ;
39- }
40- }
41-
42- // Use our custom subProcess provides features like EvaluateJavascript
43- if ( type == "renderer" )
44- {
45- //Add your own custom implementation of IRenderProcessHandler here
46- IRenderProcessHandler handler = null ;
47- var wcfEnabled = args . HasArgument ( CefSharpArguments . WcfEnabledArgument ) ;
48- var subProcess = wcfEnabled ? new WcfEnabledSubProcess ( parentProcessId , handler , args ) : new SubProcess ( handler , args ) ;
49-
50- using ( subProcess )
51- {
52- result = subProcess . Run ( ) ;
53- }
54- }
55- else
56- {
57- result = SubProcess . ExecuteProcess ( args ) ;
58- }
27+ var browserProcessExe = new WcfBrowserSubprocessExecutable ( ) ;
28+ var result = browserProcessExe . Main ( args , handler ) ;
5929
6030 Debug . WriteLine ( "BrowserSubprocess shutting down." ) ;
6131
6232 return result ;
6333 }
64-
65- private static async void AwaitParentProcessExit ( int parentProcessId )
66- {
67- try
68- {
69- var parentProcess = Process . GetProcessById ( parentProcessId ) ;
70- parentProcess . WaitForExit ( ) ;
71- }
72- catch ( Exception e )
73- {
74- //main process probably died already
75- Debug . WriteLine ( e ) ;
76- }
77-
78- await Task . Delay ( 1000 ) ; //wait a bit before exiting
79-
80- Debug . WriteLine ( "BrowserSubprocess shutting down forcibly." ) ;
81-
82- Process . GetCurrentProcess ( ) . Kill ( ) ;
83- }
8434 }
8535}
0 commit comments