Skip to content
This repository was archived by the owner on Jan 15, 2023. It is now read-only.

Commit 29b26f2

Browse files
committed
Fixing #237 - Adding a configurable option - UseOnlyCefMessageLoop.
1 parent cf9eb16 commit 29b26f2

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/Chromely.CefSharp/NativeHost/WinBase/NativeHostBase.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Reflection;
1010
using System.Runtime.InteropServices;
1111
using System.Threading.Tasks;
12+
using CefSharp;
1213
using Chromely.Core.Configuration;
1314
using Chromely.Core.Host;
1415
using Chromely.Core.Logging;
@@ -127,7 +128,23 @@ public virtual IntPtr GetNativeHandle()
127128

128129
public virtual void Run()
129130
{
130-
RunMessageLoopInternal();
131+
try
132+
{
133+
if (_options.UseOnlyCefMessageLoop)
134+
{
135+
Cef.RunMessageLoop();
136+
Cef.Shutdown();
137+
}
138+
else
139+
{
140+
RunMessageLoopInternal();
141+
}
142+
}
143+
catch (Exception exception)
144+
{
145+
Logger.Instance.Log.LogError("Error in NativeHostBase::Run");
146+
Logger.Instance.Log.LogError(exception, exception.Message);
147+
}
131148
}
132149

133150
public virtual Size GetWindowClientSize()
@@ -529,6 +546,11 @@ protected virtual IntPtr WndProc(IntPtr hWnd, uint message, IntPtr wParam, IntPt
529546

530547
case WM.DESTROY:
531548
{
549+
if (_options.UseOnlyCefMessageLoop)
550+
{
551+
Cef.QuitMessageLoop();
552+
}
553+
532554
PostQuitMessage(0);
533555
break;
534556
}

src/Chromely.CefSharp/WindowController.Run.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected int RunInternal(string[] args)
6363
LocalesDirPath = localesDirPath,
6464
Locale = "en-US",
6565
RemoteDebuggingPort = 20480,
66-
MultiThreadedMessageLoop = true,
66+
MultiThreadedMessageLoop = !_config.WindowOptions.UseOnlyCefMessageLoop,
6767
CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"),
6868
LogSeverity = LogSeverity.Default,
6969
LogFile = "logs\\chromely.cef_" + DateTime.Now.ToString("yyyyMMdd") + ".log",
@@ -74,6 +74,10 @@ protected int RunInternal(string[] args)
7474
_settings.UpdateCommandOptions(_config.CommandLineOptions);
7575
_settings.UpdateCommandLineArgs(_config.CommandLineArgs);
7676

77+
// If MultiThreadedMessageLoop is overriden in Setting using CustomSettings, then
78+
// It is assumed that the developer way not be aware of IWindowOptions - UseOnlyCefMessageLoop
79+
_config.WindowOptions.UseOnlyCefMessageLoop = !_settings.MultiThreadedMessageLoop;
80+
7781
// Set DevTools url
7882
string devtoolsUrl = _config.DevToolsUrl;
7983
if (string.IsNullOrWhiteSpace(devtoolsUrl))

0 commit comments

Comments
 (0)