/// <summary> /// Create a new <see cref="CancelationSource"/> that will be canceled either when you cancel it, or when the given token is canceled (with the same value), whichever is first. /// <para/>Note: the new <see cref="CancelationSource"/> still must be disposed when you are finished with it. /// </summary> /// <param name="token">The cancelation token to observe.</param> /// <returns>A new <see cref="CancelationSource"/> that is linked to the source token.</returns> public static CancelationSource New(CancelationToken token) { ValidateThreadAccess(1); CancelationSource newCancelationSource = New(); token.MaybeLinkSourceInternal(newCancelationSource._ref); return(newCancelationSource); }
/// <summary> /// Create a new <see cref="CancelationSource"/> that will be canceled either when you cancel it, or when any of the given tokens are canceled (with the same value), whichever is first. /// <para/>Note: the new <see cref="CancelationSource"/> still must be disposed when you are finished with it. /// </summary> /// <param name="token1">The first cancelation token to observe.</param> /// <param name="token2">The second cancelation token to observe.</param> /// <returns>A new <see cref="CancelationSource"/> that is linked to the source token.</returns> public static CancelationSource New(CancelationToken token1, CancelationToken token2) { ValidateThreadAccess(1); CancelationSource newCancelationSource = New(token1); if (!newCancelationSource._ref.IsCanceled) { token2.MaybeLinkSourceInternal(newCancelationSource._ref); } return(newCancelationSource); }