Fixes #4920. Re-enter RunLoop when End is cancelled by IsRunningChanging#4921
Merged
YourRobotOverlord merged 4 commits intogui-cs:developfrom Apr 10, 2026
Conversation
When an IsRunningChanging handler vetoed a stop (e.g. 'Are you sure?' pattern), End() returned early but Run() also returned - leaving IsRunning=true, StopRequested=true, and no event loop running, causing an application freeze. Fix: wrap the try/finally in ApplicationImpl.Run() in a while(true) loop. After End() returns, check runnable.IsRunning: - false -> End succeeded, break (no behaviour change) - true -> End was cancelled, reset StopRequested=false and re-enter RunLoop Also adds: - UICatalog scenario CancelStopDemo to reproduce the freeze visually - Regression test Run_WhenStopCancelledByIsRunningChanging_RunLoopResumes Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…e/description - Rename file CancelStopDemo.cs → IsRunningChangingCancelDemo.cs - Rename class CancelStopDemo → IsRunningChangingCancelDemo - ScenarioMetadata name: 'IsRunningChanging Cancel Demo' - ScenarioMetadata description: 'Demonstrates vetoing a stop by overriding OnIsRunningChanging — the dialog stays interactive after the user chooses Stay' - Update XML doc comments to lead with OnIsRunningChanging rather than 'cancel stop pattern' Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
tig
requested changes
Apr 10, 2026
Unit tests provide sufficient coverage; the UICatalog scenario is not needed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
tig
approved these changes
Apr 10, 2026
This was referenced May 1, 2026
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.
Fixes #4920.
Problem
See the linked issue. When
OnIsRunningChanging(or anIsRunningChangingevent handler) vetoes a stop,ApplicationImpl.Run()returned early leaving the runnable withIsRunning=true,StopRequested=true, and no event loop active — a freeze or crash.Fix
In
ApplicationImpl.Run(), wrap theRunLoop / Endblock in awhile(true)loop and only break whenEnd()succeeds (i.e.runnable.IsRunning == false). WhenEndis cancelled, resetStopRequested=falseand re-enterRunLoop:Why This Is Safe
IsRunningbecomes false afterEnd, loop breaksRunLoopEndruns infinally, exception propagatesIsRunningChangingRun()returns early; runnable deadRunLoopre-entered; runnable stays interactiveChanges
Terminal.Gui/App/ApplicationImpl.Run.cstry/finallyinwhile(true)loopTests/UnitTestsParallelizable/Application/ApplicationImplTests.csRun_WhenStopCancelledByIsRunningChanging_RunLoopResumesExamples/UICatalog/Scenarios/IsRunningChangingCancelDemo.csOnIsRunningChangingveto pattern