ExecutionContext and SynchronizationContext deep dive#52890
Open
BillWagner wants to merge 8 commits intodotnet:mainfrom
Open
ExecutionContext and SynchronizationContext deep dive#52890BillWagner wants to merge 8 commits intodotnet:mainfrom
BillWagner wants to merge 8 commits intodotnet:mainfrom
Conversation
1. Create `executioncontext-and-synchronizationcontext.md` — from "ExecutionContext vs SynchronizationContext." Covers what each context is, what "flow" means, how async/await interacts with both, why `SynchronizationContext.Current` doesn't flow across awaits. *Most popular post (20 reactions), no existing equivalent.* 1. Create `synchronizationcontext-and-console-apps.md` — from "Await, SynchronizationContext, and Console Apps" parts 1-3. **Needs significant update:** add `async Task Main()`, top-level statements, modern .NET runtime behavior. 1. Add both to TOC after the wrapper articles.
74e85ff to
17f8935
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds two new conceptual articles that explain how ExecutionContext and SynchronizationContext relate to async/await, and how console apps behave (and how to build a single-threaded pump when you need thread affinity).
Changes:
- Add
executioncontext-synchronizationcontext.mdwith runnable C# and Visual Basic snippets. - Add
synchronizationcontext-console-apps.mdincluding anAsyncPump-style implementation and snippets. - Add both new articles to the advanced programming navigation TOC.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 17 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/standard/asynchronous-programming-patterns/executioncontext-synchronizationcontext.md | New conceptual article explaining both contexts, flow, and await interactions. |
| docs/standard/asynchronous-programming-patterns/snippets/executioncontext-synchronizationcontext/csharp/Program.cs | C# runnable snippet backing the ExecutionContext/SynchronizationContext article. |
| docs/standard/asynchronous-programming-patterns/snippets/executioncontext-synchronizationcontext/csharp/ExecutionContextAndSyncContext.csproj | C# project for building/running the snippet. |
| docs/standard/asynchronous-programming-patterns/snippets/executioncontext-synchronizationcontext/vb/Program.vb | Visual Basic runnable snippet backing the article. |
| docs/standard/asynchronous-programming-patterns/snippets/executioncontext-synchronizationcontext/vb/ExecutionContextAndSyncContext.vbproj | Visual Basic project for building/running the snippet. |
| docs/standard/asynchronous-programming-patterns/synchronizationcontext-console-apps.md | New article explaining console default behavior and a custom single-threaded context/pump. |
| docs/standard/asynchronous-programming-patterns/snippets/synchronizationcontext-console-apps/csharp/Program.cs | C# runnable snippet implementing the custom context and pump. |
| docs/standard/asynchronous-programming-patterns/snippets/synchronizationcontext-console-apps/csharp/SyncContextConsoleApps.csproj | C# project for building/running the snippet. |
| docs/standard/asynchronous-programming-patterns/snippets/synchronizationcontext-console-apps/vb/Program.vb | Visual Basic runnable snippet implementing the custom context and pump. |
| docs/standard/asynchronous-programming-patterns/snippets/synchronizationcontext-console-apps/vb/SyncContextConsoleApps.vbproj | Visual Basic project for building/running the snippet. |
| docs/navigate/advanced-programming/toc.yml | Adds both new articles to the navigation TOC. |
...chronous-programming-patterns/snippets/synchronizationcontext-console-apps/csharp/Program.cs
Show resolved
Hide resolved
...chronous-programming-patterns/snippets/synchronizationcontext-console-apps/csharp/Program.cs
Show resolved
Hide resolved
...chronous-programming-patterns/snippets/synchronizationcontext-console-apps/csharp/Program.cs
Outdated
Show resolved
Hide resolved
docs/standard/asynchronous-programming-patterns/synchronizationcontext-console-apps.md
Outdated
Show resolved
Hide resolved
docs/standard/asynchronous-programming-patterns/executioncontext-synchronizationcontext.md
Outdated
Show resolved
Hide resolved
...nous-programming-patterns/snippets/executioncontext-synchronizationcontext/csharp/Program.cs
Show resolved
Hide resolved
...chronous-programming-patterns/snippets/executioncontext-synchronizationcontext/vb/Program.vb
Show resolved
Hide resolved
...chronous-programming-patterns/snippets/executioncontext-synchronizationcontext/vb/Program.vb
Show resolved
Hide resolved
docs/standard/asynchronous-programming-patterns/synchronizationcontext-console-apps.md
Outdated
Show resolved
Hide resolved
docs/standard/asynchronous-programming-patterns/executioncontext-synchronizationcontext.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
Fix feedback, and one final edit pass
…nto async-aweigh-2
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.
Contributes to #17714
executioncontext-and-synchronizationcontext.md— from "ExecutionContext vs SynchronizationContext." Covers what each context is, what "flow" means, how async/await interacts with both, whySynchronizationContext.Currentdoesn't flow across awaits. Most popular post (20 reactions), no existing equivalent.synchronizationcontext-and-console-apps.md— from "Await, SynchronizationContext, and Console Apps" parts 1-3. Needs significant update: addasync Task Main(), top-level statements, modern .NET runtime behavior.Summary
Describe your changes here.
Fixes #Issue_Number (if available)
Internal previews