Skip to content

Add simple parent-child linked cancellation token example#52330

Open
Copilot wants to merge 3 commits intomainfrom
copilot/add-parent-child-tokens-example
Open

Add simple parent-child linked cancellation token example#52330
Copilot wants to merge 3 commits intomainfrom
copilot/add-parent-child-tokens-example

Conversation

Copy link
Contributor

Copilot AI commented Mar 17, 2026

The "Cancellation in Managed Threads" article lacked a basic example of CreateLinkedTokenSource for the parent-child pattern — the most common reason developers reach for linked tokens.

Changes

  • New snippets (docs/standard/threading/snippets/cancellation-in-managed-threads/{csharp,vb}/LinkedTokens/): self-contained C# and VB console projects demonstrating the minimal parent-child pattern
  • Article update (cancellation-in-managed-threads.md): restructured "Listening to multiple tokens simultaneously" to lead with the simple example before the existing complex class-based scenario; updated ms.date and added ai-usage: ai-assisted
using var parentCts = new CancellationTokenSource();
using var childCts = CancellationTokenSource.CreateLinkedTokenSource(parentCts.Token);

parentCts.Cancel();

Console.WriteLine(parentCts.Token.IsCancellationRequested); // True
Console.WriteLine(childCts.Token.IsCancellationRequested);  // True
Original prompt

This section details on the original issue you should resolve

<issue_title>Missing simple example how to create parent-child tokens</issue_title>
<issue_description>
[Enter feedback here]

Something like the following, which must be the most common use case for linking.

https://stackoverflow.com/questions/29623178/linking-cancellation-tokens


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Comments on the Issue (you are @copilot in this section)

@tdykstra Thanks for the suggestion - we'll add an example the next time the article is updated.

📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.


Internal previews

📄 File 🔗 Preview link
docs/standard/threading/cancellation-in-managed-threads.md docs/standard/threading/cancellation-in-managed-threads

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
Copilot AI changed the title [WIP] Add simple example for creating parent-child tokens Add simple parent-child linked cancellation token example Mar 17, 2026
Copilot AI requested a review from BillWagner March 17, 2026 18:25
@BillWagner BillWagner marked this pull request as ready for review March 17, 2026 21:06
@BillWagner BillWagner requested a review from a team as a code owner March 17, 2026 21:06
Copilot AI review requested due to automatic review settings March 17, 2026 21:06
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready for final review.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Cancellation in Managed Threads documentation to include a minimal parent-child linked cancellation token example using CancellationTokenSource.CreateLinkedTokenSource, supported by new self-contained C# and Visual Basic snippet projects.

Changes:

  • Added new C# and VB console snippet projects demonstrating a simple parent→child linked token pattern.
  • Restructured the “Listening to multiple tokens simultaneously” section to lead with the new simple example before the existing more complex scenario.
  • Updated article frontmatter (ms.date, and ai-usage).

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
docs/standard/threading/snippets/cancellation-in-managed-threads/csharp/LinkedTokens/Program.cs Adds the minimal C# linked-token example used by the article.
docs/standard/threading/snippets/cancellation-in-managed-threads/csharp/LinkedTokens/LinkedTokens.csproj Adds a self-contained C# console project to build/run the snippet.
docs/standard/threading/snippets/cancellation-in-managed-threads/vb/LinkedTokens/Program.vb Adds the minimal VB linked-token example used by the article.
docs/standard/threading/snippets/cancellation-in-managed-threads/vb/LinkedTokens/LinkedTokens.vbproj Adds a self-contained VB console project to build/run the snippet.
docs/standard/threading/cancellation-in-managed-threads.md Reorders and expands the linked-token section, and embeds the new snippets.

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
Copilot AI requested a review from BillWagner March 17, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing simple example how to create parent-child tokens

3 participants