private void OnStartup(object sender, StartupEventArgs e) { AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; RunnerHelper.WaitForPowerToysRunner(PowerToysPID, () => { Environment.Exit(0); }); _themeManager = new ThemeManager(this); if (!FancyZonesEditorIO.ParseParams().Result) { FancyZonesEditorIO.ParseCommandLineArguments(); } var parseResult = FancyZonesEditorIO.ParseZoneSettings(); // 10ms retry loop with 1 second timeout if (!parseResult.Result) { CancellationTokenSource ts = new CancellationTokenSource(); Task t = Task.Run(() => { while (!parseResult.Result && !ts.IsCancellationRequested) { Task.Delay(10).Wait(); parseResult = FancyZonesEditorIO.ParseZoneSettings(); } }); try { bool result = t.Wait(1000, ts.Token); ts.Cancel(); } catch (OperationCanceledException) { ts.Dispose(); } } // Error message if parsing failed if (!parseResult.Result) { var sb = new StringBuilder(); sb.AppendLine(); sb.AppendLine("## " + ParsingErrorReportTag); sb.AppendLine(); sb.AppendLine(parseResult.Message); sb.AppendLine(); sb.AppendLine(ParsingErrorDataTag); sb.AppendLine(parseResult.MalformedData); string message = parseResult.Message + Environment.NewLine + Environment.NewLine + FancyZonesEditor.Properties.Resources.Error_Parsing_Zones_Settings_User_Choice; if (MessageBox.Show(message, FancyZonesEditor.Properties.Resources.Error_Parsing_Zones_Settings_Title, MessageBoxButton.YesNo) == MessageBoxResult.No) { // TODO: log error ShowExceptionReportMessageBox(sb.ToString()); Environment.Exit(0); } ShowExceptionReportMessageBox(sb.ToString()); } MainWindowSettingsModel settings = ((App)Current).MainWindowSettings; settings.UpdateSelectedLayoutModel(); Overlay.Show(); }