Skip to content

Commit 17dcfc4

Browse files
committed
Use MultiThreadedMessageLoop = false
1 parent 40b01d6 commit 17dcfc4

2 files changed

Lines changed: 46 additions & 9 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
3+
namespace CefSharp.OutOfProcess.BrowserProcess
4+
{
5+
public class BrowserProcessHandler : CefSharp.Handler.BrowserProcessHandler
6+
{
7+
private readonly int _parentProcessId;
8+
private readonly IntPtr _hostHwnd;
9+
10+
public BrowserProcessHandler(int parentProcessId, IntPtr hostHwnd)
11+
{
12+
_parentProcessId = parentProcessId;
13+
_hostHwnd = hostHwnd;
14+
}
15+
16+
protected override void OnContextInitialized()
17+
{
18+
base.OnContextInitialized();
19+
20+
var browser = new ChromiumWebBrowser("https://github.com");
21+
22+
var windowInfo = new WindowInfo();
23+
windowInfo.WindowName = "CefSharpBrowserProcess";
24+
windowInfo.SetAsChild(_hostHwnd);
25+
26+
browser.CreateBrowser(windowInfo);
27+
}
28+
}
29+
}

CefSharp.OutOfProcess.BrowserProcess/Program.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Diagnostics;
33
using System.IO;
4+
using System.Threading.Tasks;
45
using CefSharp.Internals;
56

67
namespace CefSharp.OutOfProcess.BrowserProcess
@@ -11,7 +12,7 @@ public static int Main(string[] args)
1112
{
1213
Cef.EnableHighDPISupport();
1314

14-
//Debugger.Launch();
15+
Debugger.Launch();
1516

1617
var parentProcessId = int.Parse(CommandLineArgsParser.GetArgumentValue(args, "--parentProcessId"));
1718
var hostHwnd = int.Parse(CommandLineArgsParser.GetArgumentValue(args, "--hostHwnd"));
@@ -21,22 +22,29 @@ public static int Main(string[] args)
2122
var settings = new CefSettings()
2223
{
2324
//By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
24-
CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\OutOfProcessCache")
25+
CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\OutOfProcessCache"),
26+
MultiThreadedMessageLoop = false
2527
};
2628

29+
var browserProcessHandler = new BrowserProcessHandler(parentProcessId, new IntPtr(hostHwnd));
30+
2731
Cef.EnableWaitForBrowsersToClose();
2832

29-
Cef.Initialize(settings);
33+
Cef.Initialize(settings, performDependencyCheck:true, browserProcessHandler: browserProcessHandler);
3034

31-
var browser = new ChromiumWebBrowser("https://github.com");
35+
Task.Run(() =>
36+
{
37+
parentProcess.WaitForExit();
3238

33-
var windowInfo = new WindowInfo();
34-
windowInfo.WindowName = "CefSharpBrowserProcess";
35-
windowInfo.SetAsChild(new IntPtr(hostHwnd));
39+
CefThread.ExecuteOnUiThread(() =>
40+
{
41+
Cef.QuitMessageLoop();
3642

37-
browser.CreateBrowser(windowInfo);
43+
return true;
44+
});
45+
});
3846

39-
parentProcess.WaitForExit();
47+
Cef.RunMessageLoop();
4048

4149
Cef.WaitForBrowsersToClose();
4250

0 commit comments

Comments
 (0)