//-------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // File: CancellationTokenExtensions.cs // //-------------------------------------------------------------------------- using System.Collections.Concurrent.Partitioners; using System.Collections.Generic; namespace System.Threading { /// <summary>Extension methods for CancellationToken.</summary> public static class CancellationTokenExtensions { /// <summary>Cancels a CancellationTokenSource and throws a corresponding OperationCanceledException.</summary> /// <param name="source">The source to be canceled.</param> public static void CancelAndThrow(this CancellationTokenSource source) { source.Cancel(); source.Token.ThrowIfCancellationRequested(); } /// <summary> /// Creates a CancellationTokenSource that will be canceled when the specified token has cancellation requested. /// </summary> /// <param name="token">The token.</param> /// <returns>The created CancellationTokenSource.</returns> public static CancellationTokenSource CreateLinkedSource(this CancellationToken token) { return CancellationTokenSource.CreateLinkedTokenSource(token, new CancellationToken()); } } }
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)