Skip to content

Commit 65eef56

Browse files
committed
Add support for Synchronous Bindings when Self Hosting BrowserSubProcess
Resolves #4562
1 parent 1328732 commit 65eef56

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

CefSharp.BrowserSubprocess.Core/BrowserSubprocessExecutable.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ namespace CefSharp
2828

2929
}
3030

31+
#ifdef NETCOREAPP
3132
/// <summary>
3233
/// This function should be called from the application entry point function (typically Program.Main)
3334
/// to execute a secondary process e.g. gpu, renderer, utility
3435
/// This overload is specifically used for .Net Core. For hosting your own BrowserSubProcess
3536
/// it's preferable to use the Main method provided by this class.
36-
/// - Obtains the command line args via a call to Environment::GetCommandLineArgs
3737
/// </summary>
3838
/// <returns>
3939
/// If called for the browser process (identified by no "type" command-line value) it will return immediately
@@ -45,6 +45,7 @@ namespace CefSharp
4545
auto subProcess = gcnew BrowserSubprocessExecutable();
4646
return subProcess->Main(args, nullptr);
4747
}
48+
#endif
4849

4950
/// <summary>
5051
/// This function should be called from the application entry point function (typically Program.Main)

CefSharp.BrowserSubprocess.Core/WcfBrowserSubprocessExecutable.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@ namespace CefSharp
3131
{
3232

3333
}
34+
35+
/// <summary>
36+
/// This function should be called from the application entry point function (typically Program.Main)
37+
/// to execute a secondary process e.g. gpu, renderer, utility
38+
/// This overload is specifically used for .Net 4.x. For hosting your own BrowserSubProcess
39+
/// it's preferable to use the Main method provided by this class.
40+
/// </summary>
41+
/// <returns>
42+
/// If called for the browser process (identified by no "type" command-line value) it will return immediately
43+
/// with a value of -1. If called for a recognized secondary process it will block until the process should exit
44+
/// and then return the process exit code.
45+
/// </returns
46+
static int MainSelfHost(array<String^>^ args)
47+
{
48+
auto subProcess = gcnew WcfBrowserSubprocessExecutable();
49+
return subProcess->Main(args, nullptr);
50+
}
51+
3452
protected:
3553
SubProcess^ GetSubprocess(IEnumerable<String^>^ args, int parentProcessId, IRenderProcessHandler^ handler) override
3654
{

CefSharp.Core/BrowserSubprocess/SelfHost.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,13 @@ public static int Main(string[] args)
7777
browserSubprocessDllPath = Path.Combine(Path.GetDirectoryName(typeof(CefSharp.Core.BrowserSettings).Assembly.Location), "CefSharp.BrowserSubprocess.Core.dll");
7878
}
7979
var browserSubprocessDll = System.Runtime.Loader.AssemblyLoadContext.Default.LoadFromAssemblyPath(browserSubprocessDllPath);
80+
var browserSubprocessExecutableType = browserSubprocessDll.GetType("CefSharp.BrowserSubprocess.BrowserSubprocessExecutable");
8081
#else
8182
var browserSubprocessDllPath = Path.Combine(Path.GetDirectoryName(typeof(CefSharp.Core.BrowserSettings).Assembly.Location), "CefSharp.BrowserSubprocess.Core.dll");
8283
var browserSubprocessDll = System.Reflection.Assembly.LoadFrom(browserSubprocessDllPath);
83-
84+
var browserSubprocessExecutableType = browserSubprocessDll.GetType("CefSharp.BrowserSubprocess.WcfBrowserSubprocessExecutable");
8485
#endif
85-
var browserSubprocessExecutableType = browserSubprocessDll.GetType("CefSharp.BrowserSubprocess.BrowserSubprocessExecutable");
86+
8687
var browserSubprocessExecutable = Activator.CreateInstance(browserSubprocessExecutableType);
8788

8889
var mainMethod = browserSubprocessExecutableType.GetMethod("MainSelfHost", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);

0 commit comments

Comments
 (0)