Let the viewer close when Windows is shutting down - #778
Merged
Conversation
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.
This was referenced Aug 26, 2026
This was referenced Aug 27, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.