/// <summary> /// Custom windows message pumping to fix frame stuck issue. /// Normally, you need call this method in <see cref="Application.Idle" /> handler. /// </summary> public static void PumpMessage() { if (!Enabled) { return; } if (!TextServicesLoader.ServicesInstalled) { return; } bool result; var msg = new NativeMethods.NativeMessage(); do { result = NativeMethods.PeekMessage(out msg, _windowHandle, 0, 0, NativeMethods.PM_REMOVE); if (result) { NativeMethods.TranslateMessage(ref msg); NativeMethods.DispatchMessage(ref msg); } } while (result); NativeMethods.PostMessage(_windowHandle, NativeMethods.WM_NULL, IntPtr.Zero, IntPtr.Zero); }
/// <inheritdoc /> public void FlushMessageQueue() { CheckInitialization(); if (_contextProvider.UiContext == SynchronizationContext.Current) { PumpMessages(); } else { InvokeAsync(PumpMessages); } // This should remain a local function - messages should not be pumped out outside of FlushMessageQueue. void PumpMessages() { var message = new NativeMethods.NativeMessage(); var handle = GCHandle.Alloc(message); while (NativeMethods.PeekMessage(ref message, IntPtr.Zero, 0, 0, NativeMethods.PeekMessageRemoval.Remove)) { NativeMethods.TranslateMessage(ref message); NativeMethods.DispatchMessage(ref message); } handle.Free(); } }