METHOD

CancellationTokenSource.CreateLinkedTokenSource

Creates an owned source that becomes canceled when either supplied token requests cancellation. Canceling the linked source does not cancel its parents. Dispose the linked source after its users complete.

Formal Syntax & Structure

csharp syntaxcsharp
CancellationTokenSource.CreateLinkedTokenSource(first, second)

Working Example

Example Snippetcsharp
using System;using System.Threading;using System.Threading.Tasks;using var a = new CancellationTokenSource(); using var b = new CancellationTokenSource(); using var linked = CancellationTokenSource.CreateLinkedTokenSource(a.Token,b.Token); b.Cancel(); Console.WriteLine(linked.IsCancellationRequested); // True
C# & .NET Reference