Skip to content

Let the viewer close when Windows is shutting down - #778

Merged
SimonCropp merged 2 commits into
mainfrom
fix-viewer-blocks-windows-shutdown
Aug 21, 2026
Merged

Let the viewer close when Windows is shutting down#778
SimonCropp merged 2 commits into
mainfrom
fix-viewer-blocks-windows-shutdown

Conversation

@SimonCropp

Copy link
Copy Markdown
Member

OnFormClosing cancelled every close, whatever the CloseReason. For a close the user asked for that is right: whether closing means hide or exit is ViewerProgram's rule and it needs a tray check to decide, so the form defers and CloseForReal brings the answer back.

For the close Windows sends when the session is ending it is not. WinForms answers WM_QUERYENDSESSION with !e.Cancel, so a viewer that was open at shutdown told Windows it was preventing one, and the user got the "DiffEngineViewer is preventing shutdown" screen. With a tray running it was worse than a prompt: the loop's answer to a close request is to hide the window, so the process stayed up and went on blocking until the user chose "Shut down anyway".

Do not cancel when the reason is WindowsShutDown or TaskManagerClosing. Both mean the process is going away regardless, so refusing buys nothing. Letting the close through is safe: the loop already watches for a disposed form and returns, running the same shutdown it would have run anyway.

OnFormClosing cancelled every close, whatever the CloseReason. For a close the
user asked for that is right: whether closing means hide or exit is
ViewerProgram's rule and it needs a tray check to decide, so the form defers and
CloseForReal brings the answer back.

For the close Windows sends when the session is ending it is not. WinForms
answers WM_QUERYENDSESSION with !e.Cancel, so a viewer that was open at shutdown
told Windows it was preventing one, and the user got the "DiffEngineViewer is
preventing shutdown" screen. With a tray running it was worse than a prompt: the
loop's answer to a close request is to hide the window, so the process stayed up
and went on blocking until the user chose "Shut down anyway".

Do not cancel when the reason is WindowsShutDown or TaskManagerClosing. Both
mean the process is going away regardless, so refusing buys nothing. Letting the
close through is safe: the loop already watches for a disposed form and returns,
running the same shutdown it would have run anyway.
@SimonCropp SimonCropp added this to the 20.0.0 milestone Aug 21, 2026
@SimonCropp
SimonCropp merged commit ca2ebe0 into main Aug 21, 2026
8 checks passed
@SimonCropp
SimonCropp deleted the fix-viewer-blocks-windows-shutdown branch August 21, 2026 12:32
This was referenced Aug 26, 2026
This was referenced Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant