Skip to content

Commit fe11f2e

Browse files
committed
Add Cef.DoMessageLoopWork example to WinForms.Example project
1 parent 221ec0d commit fe11f2e

4 files changed

Lines changed: 19 additions & 4 deletions

File tree

CefSharp.Example/CefExample.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static class CefExample
2727
private static readonly bool DebuggingSubProcess = Debugger.IsAttached;
2828
private static string PluginInformation = "";
2929

30-
public static void Init(bool osr)
30+
public static void Init(bool osr, bool multiThreadedMessageLoop)
3131
{
3232
// Set Google API keys, used for Geolocation requests sans GPS. See http://www.chromium.org/developers/how-tos/api-keys
3333
// Environment.SetEnvironmentVariable("GOOGLE_API_KEY", "");
@@ -73,6 +73,8 @@ public static void Init(bool osr)
7373
//Possibly useful when experiencing blury fonts.
7474
//settings.CefCommandLineArgs.Add("disable-direct-write", "1");
7575

76+
settings.MultiThreadedMessageLoop = multiThreadedMessageLoop;
77+
7678
// Off Screen rendering (WPF/Offscreen)
7779
if(osr)
7880
{

CefSharp.OffScreen.Example/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static void Main(string[] args)
2222
Console.WriteLine();
2323

2424
// You need to replace this with your own call to Cef.Initialize();
25-
CefExample.Init(true);
25+
CefExample.Init(true, multiThreadedMessageLoop:true);
2626

2727
MainAsync("cachePath1", 1.0);
2828
//Demo showing Zoom Level of 3.0

CefSharp.WinForms.Example/Program.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,20 @@ public static void Main()
2222
}
2323
#endif
2424

25-
CefExample.Init(false);
25+
const bool multiThreadedMessageLoop = true;
26+
CefExample.Init(false, multiThreadedMessageLoop: multiThreadedMessageLoop);
27+
28+
if(multiThreadedMessageLoop == false)
29+
{
30+
//http://magpcss.org/ceforum/apidocs3/projects/%28default%29/%28_globals%29.html#CefDoMessageLoopWork%28%29
31+
//Perform a single iteration of CEF message loop processing.
32+
//This function is used to integrate the CEF message loop into an existing application message loop.
33+
//Care must be taken to balance performance against excessive CPU usage.
34+
//This function should only be called on the main application thread and only if CefInitialize() is called with a CefSettings.multi_threaded_message_loop value of false.
35+
//This function will not block.
36+
37+
Application.Idle += (s, e) => Cef.DoMessageLoopWork();
38+
}
2639

2740
var browser = new BrowserForm();
2841
//var browser = new SimpleBrowserForm();

CefSharp.Wpf.Example/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ protected override void OnStartup(StartupEventArgs e)
1919
}
2020
#endif
2121

22-
CefExample.Init(true);
22+
CefExample.Init(true, multiThreadedMessageLoop: true);
2323

2424
base.OnStartup(e);
2525
}

0 commit comments

Comments
 (0)