private void MainWindow_OnClosing(object sender, CancelEventArgs e) { if (!_forceClose && _setti.MinimizeToTray && !Debugger.IsAttached) { e.Cancel = true; //abort closing Hide(); // hide instead Settings.Save(); // ... and save the config } else { Settings.Save(); //do the important stuff first! _updater.TryClose(); NotifyIcon.Dispose(); Stats.TrackAction(Stats.TrackActivity.AppTerm); } }