public void RunBackground(Action action) { CurrentBackground = new BackgroundWindow(); var t = new System.Threading.Tasks.Task(new Action(() => { try { action(); CurrentBackground.Closing -= CurrentBackground.OnClosing; Dispatcher.Invoke(CurrentBackground.Close); } catch (Exception ex) { Dispatcher.Invoke(() => { var ew = new ErrorWindow(); var tr = new Thread(new ParameterizedThreadStart(ew.ShowError)) { CurrentUICulture = new System.Globalization.CultureInfo("en-US") }; tr.Start(ex); if (ew.ShowDialog() != true) { CurrentBackground.Closing -= CurrentBackground.OnClosing; Dispatcher.Invoke(() => { CurrentBackground.Close(); Close(); }); } }); } })); t.Start(); CurrentBackground.ShowDialog(); }
public void OnUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) { var ew = new ErrorWindow(); var t = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(ew.ShowError)) { CurrentUICulture = new System.Globalization.CultureInfo("en-US") }; t.Start(e.Exception); e.Handled = true; if (ew.ShowDialog() != true) { Close(); } }