Browse Source

Fixes Issue 4980: Message loop exit when GetMessage < 0

pull/5037/head
Giuseppe Lippolis 6 years ago
parent
commit
1b0ff07133
  1. 5
      src/Avalonia.Base/Logging/LogArea.cs
  2. 4
      src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs
  3. 11
      src/Windows/Avalonia.Win32/Win32Platform.cs

5
src/Avalonia.Base/Logging/LogArea.cs

@ -34,5 +34,10 @@ namespace Avalonia.Logging
/// The log event comes from the control system.
/// </summary>
public const string Control = "Control";
/// <summary>
/// The log evevnt come from Win32Platform
/// </summary>
public const string Win32Platform = nameof(Win32Platform);
}
}

4
src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs

@ -931,8 +931,8 @@ namespace Avalonia.Win32.Interop
[DllImport("user32.dll", EntryPoint = "MapVirtualKeyW")]
public static extern uint MapVirtualKey(uint uCode, uint uMapType);
[DllImport("user32.dll", EntryPoint = "GetMessageW")]
public static extern sbyte GetMessage(out MSG lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax);
[DllImport("user32.dll", EntryPoint = "GetMessageW",SetLastError = true)]
public static extern int GetMessage(out MSG lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax);
[DllImport("user32.dll")]
public static extern int GetMessageTime();

11
src/Windows/Avalonia.Win32/Win32Platform.cs

@ -137,13 +137,18 @@ namespace Avalonia.Win32
public void RunLoop(CancellationToken cancellationToken)
{
while (!cancellationToken.IsCancellationRequested)
var result = 0;
while (!cancellationToken.IsCancellationRequested
&& (result = UnmanagedMethods.GetMessage(out var msg, IntPtr.Zero, 0, 0)) > 0)
{
UnmanagedMethods.MSG msg;
UnmanagedMethods.GetMessage(out msg, IntPtr.Zero, 0, 0);
UnmanagedMethods.TranslateMessage(ref msg);
UnmanagedMethods.DispatchMessage(ref msg);
}
if (result < 0)
{
Logging.Logger.TryGet(Logging.LogEventLevel.Error, Logging.LogArea.Win32Platform)
?.Log(this, "Unmanaged error in message loop. Error Code: {0}", Marshal.GetLastWin32Error());
}
}
public IDisposable StartTimer(DispatcherPriority priority, TimeSpan interval, Action callback)

Loading…
Cancel
Save