Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/CodeShellManager/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4767,7 +4767,15 @@ protected override async void OnClosing(System.ComponentModel.CancelEventArgs e)
App.TrayIcon?.Dispose();

_shutdownComplete = true;
Close();
// Queue Close() on the dispatcher rather than calling it inline. If none of
// the awaits above actually yielded (e.g. --clean mode with no sessions —
// SaveStateAsync short-circuits, and the foreach loops over an empty list
// never await), control never returns to WPF between e.Cancel=true and this
// point, so WPF's internal _isClosing flag is still set and Close() throws
// "Cannot ... call Close ... while a Window is closing." Posting via
// BeginInvoke lets OnClosing return first, WPF resets _isClosing, then the
// queued Close() re-enters cleanly through the _shutdownComplete branch.
_ = Dispatcher.BeginInvoke(new System.Action(Close));
}

/// <summary>
Expand Down
Loading