static public void QuitWindowsEventLoop() { if (IsWindowsEventLoopQuitRequested) { return; } MainThreadSynchronizationContext.Send(delegate { if (IsWindowsEventLoopQuitRequested) { return; } IsWindowsEventLoopQuitRequested = true; #if SUPPORT_WPF if (LoopMode == EventLoopMode.WPF) { _wpfapp?.Shutdown(); } #endif if (LoopMode == EventLoopMode.LibCef) { LibCefInterop.cef_quit_message_loop(); } if (LoopMode == EventLoopMode.WinForms) { WF.Application.Exit(); //This is not a good solution, hang } }, null); }
static public void InvokeInAppThread(Action handler) { if (handler == null) throw new ArgumentNullException(nameof(handler)); MainThreadSynchronizationContext.Send(delegate { handler(); }, null); }