Fixes #5579. SynchronizationContext is not correctly implemented in v2#5588
Merged
Conversation
…d guarantee set the sync context for the current running app.
Contributor
There was a problem hiding this comment.
Pull request overview
Addresses #5579 by restoring a Terminal.Gui main-loop-backed SynchronizationContext so async/await continuations resume on the app’s main thread in v2.
Changes:
- Reintroduces
MainLoopSyncContextand sets it duringApplicationImpl.Initand sessionBegin. - Adds unit tests asserting
SynchronizationContext.Postruns on the app’s main thread and is instance-specific. - Updates
MainLoopCoordinatorto avoid capturing synchronization context during startup waits.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/UnitTestsParallelizable/Application/ApplicationImplTests.cs | Adds tests validating SynchronizationContext posts back to the app main thread and is per-app-instance. |
| Terminal.Gui/App/MainLoop/MainLoopSyncContext.cs | Implements an app-instance-backed SynchronizationContext that marshals work to the app via Invoke. |
| Terminal.Gui/App/MainLoop/MainLoopCoordinator.cs | Uses ConfigureAwait (false) while awaiting startup tasks to avoid context capture. |
| Terminal.Gui/App/ApplicationImpl.Run.cs | Ensures the app’s main-loop sync context is set when a session begins. |
| Terminal.Gui/App/ApplicationImpl.Lifecycle.cs | Creates and installs the app’s MainLoopSyncContext during Init. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
tig
approved these changes
Jul 9, 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
Proposed Changes/Todos
Pull Request checklist:
CTRL-K-Dto automatically reformat your files before committing.dotnet testbefore commit///style comments)