public static void Show(Bitmap?expected, Bitmap actual) { if (actual is null) { throw new System.ArgumentNullException(nameof(actual)); } var dispatcher = WpfDispatcher.Create(); dispatcher !.Invoke(() => { var window = new ImageDiffWindow(expected, actual); _ = window.ShowDialog(); }); dispatcher.InvokeShutdown(); _ = dispatcher.Thread.Join(1000); }
public static void Show(Bitmap expected, Bitmap actual) { using (var startedEvent = new ManualResetEventSlim(initialState: false)) { System.Windows.Threading.Dispatcher dispatcher = null; var uiThread = new Thread(() => { // Create and install a new dispatcher context SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher)); dispatcher = Dispatcher.CurrentDispatcher; // Signal that it is initialized // ReSharper disable once AccessToDisposedClosure startedEvent.Set(); // Start the dispatcher processing Dispatcher.Run(); }); // Set the apartment state uiThread.SetApartmentState(ApartmentState.STA); // Make the thread a background thread uiThread.IsBackground = true; // Start the thread uiThread.Start(); startedEvent.Wait(); dispatcher.Invoke(() => { var window = new ImageDiffWindow(expected, actual); window.ShowDialog().IgnoreReturnValue(); }); dispatcher.InvokeShutdown(); uiThread.Join(1000).IgnoreReturnValue(); } }