Open
Conversation
Contributes to dotnet#17714 1. Create `cancel-non-cancelable-async-operations.md` — from "How do I cancel non-cancelable async operations?" Covers the 3 meanings of cancellation, the `WithCancellation<T>` extension method pattern using `Task.WhenAny`. **Update:** note that many .NET Core streams are now fully cancelable; `NetworkStream` async operations honor tokens. 1. Create `coalescing-cancellation-tokens-from-timeouts.md` — from "Coalescing CancellationTokens from timeouts." Covers combining a user-provided `CancellationToken` with timeout-based tokens using `CancellationTokenSource.CreateLinkedTokenSource`. **Update** for modern API surface. 1. Add both to TOC near existing cancellation content.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds two new conceptual docs on modern .NET cancellation patterns, plus runnable C# and Visual Basic snippets, and links the new docs from the advanced programming TOC.
Changes:
- Add a doc and snippets for canceling non-cancelable async operations, including the
WithCancellation<T>/Task.WhenAny“cancel the wait” pattern, and guidance for observing late faults. - Add a doc and snippets for coalescing caller cancellation with timeout cancellation via
CancellationTokenSource.CreateLinkedTokenSource, plus aWaitAsynctimeout alternative. - Link both new docs in
docs/navigate/advanced-programming/toc.yml.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| docs/standard/asynchronous-programming-patterns/cancel-non-cancelable-async-operations.md | New conceptual article describing cancellation semantics and patterns, with snippet references. |
| docs/standard/asynchronous-programming-patterns/coalesce-cancellation-tokens-from-timeouts.md | New conceptual article describing linked token sources and timeout alternatives, with snippet references. |
| docs/navigate/advanced-programming/toc.yml | Adds the two new articles to the advanced programming TOC. |
| docs/standard/asynchronous-programming-patterns/snippets/cancel-non-cancelable-async-operations/csharp/Program.cs | C# runnable snippets for token-aware APIs, WithCancellation<T>, cancel-both, and late-fault observation. |
| docs/standard/asynchronous-programming-patterns/snippets/cancel-non-cancelable-async-operations/csharp/CancelNonCancelableAsyncOperations.csproj | C# project file for compiling the new snippets. |
| docs/standard/asynchronous-programming-patterns/snippets/cancel-non-cancelable-async-operations/vb/Program.vb | VB runnable snippets mirroring the C# examples. |
| docs/standard/asynchronous-programming-patterns/snippets/cancel-non-cancelable-async-operations/vb/CancelNonCancelableAsyncOperations.vbproj | VB project file for compiling the new snippets. |
| docs/standard/asynchronous-programming-patterns/snippets/coalescing-cancellation-tokens-from-timeouts/csharp/Program.cs | C# runnable snippets for linked CTS timeouts and WaitAsync timeout semantics. |
| docs/standard/asynchronous-programming-patterns/snippets/coalescing-cancellation-tokens-from-timeouts/csharp/CoalescingCancellationTokensFromTimeouts.csproj | C# project file for compiling the new snippets. |
| docs/standard/asynchronous-programming-patterns/snippets/coalescing-cancellation-tokens-from-timeouts/vb/Program.vb | VB runnable snippets mirroring the C# linked CTS and WaitAsync examples. |
| docs/standard/asynchronous-programming-patterns/snippets/coalescing-cancellation-tokens-from-timeouts/vb/CoalescingCancellationTokensFromTimeouts.vbproj | VB project file for compiling the new snippets. |
...nchronous-programming-patterns/snippets/cancel-non-cancelable-async-operations/vb/Program.vb
Outdated
Show resolved
Hide resolved
...ous-programming-patterns/snippets/coalescing-cancellation-tokens-from-timeouts/vb/Program.vb
Show resolved
Hide resolved
...programming-patterns/snippets/coalescing-cancellation-tokens-from-timeouts/csharp/Program.cs
Show resolved
Hide resolved
...onous-programming-patterns/snippets/cancel-non-cancelable-async-operations/csharp/Program.cs
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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
cancel-non-cancelable-async-operations.md— from "How do I cancel non-cancelable async operations?" Covers the 3 meanings of cancellation, theWithCancellation<T>extension method pattern usingTask.WhenAny. Update: note that many .NET Core streams are now fully cancelable;NetworkStreamasync operations honor tokens.coalescing-cancellation-tokens-from-timeouts.md— from "Coalescing CancellationTokens from timeouts." Covers combining a user-providedCancellationTokenwith timeout-based tokens usingCancellationTokenSource.CreateLinkedTokenSource. Update for modern API surface.Internal previews