/// <summary> /// Shows the window. /// </summary> /// <param name="initializer">Action that will initialize <see cref="InteractiveWindow"/> before showing it.</param> public static void ShowWindow(Action <InteractiveWindow> initializer = null) { System.Threading.AutoResetEvent windowShown = new System.Threading.AutoResetEvent(false); ExecuteInSTA(() => { InteractiveWindow window = null; try { window = new InteractiveWindow(); initializer?.Invoke(window); window.Show(); windowShown.Set(); var _dispatcherFrame = new System.Windows.Threading.DispatcherFrame(); window.Closed += (obj, e) => { _dispatcherFrame.Continue = false; }; System.Windows.Threading.Dispatcher.PushFrame(_dispatcherFrame); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { windowShown.Set(); } window?.Close(); System.Windows.Threading.Dispatcher.CurrentDispatcher.InvokeShutdown(); }, waitForExecution: false); windowShown.WaitOne(); }
/// <summary> /// Shows the window as modal dialog. /// </summary> /// <param name="initializer">Action that will initialize <see cref="InteractiveWindow"/> before showing it.</param> public static void ShowModalWindow(Action <InteractiveWindow> initializer = null) { ExecuteInSTA(() => { InteractiveWindow window = null; try { window = new InteractiveWindow(); initializer?.Invoke(window); window.ShowDialog(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } window.Close(); System.Windows.Threading.Dispatcher.CurrentDispatcher.InvokeShutdown(); }); }