Rediger

Del via


TaskCompletionSource<TResult>.TrySetCanceled Method

Definition

Attempts to transition the underlying Task<TResult> into the Canceled state.

Overloads

TrySetCanceled()

Attempts to transition the underlying Task<TResult> into the Canceled state.

TrySetCanceled(CancellationToken)

Attempts to transition the underlying Task<TResult> into the Canceled state and enables a cancellation token to be stored in the canceled task.

TrySetCanceled()

Source:
TaskCompletionSource_T.cs
Source:
TaskCompletionSource_T.cs
Source:
TaskCompletionSource_T.cs

Attempts to transition the underlying Task<TResult> into the Canceled state.

public:
 bool TrySetCanceled();
public bool TrySetCanceled ();
member this.TrySetCanceled : unit -> bool
Public Function TrySetCanceled () As Boolean

Returns

true if the operation was successful; false if the operation was unsuccessful or the object has already been disposed.

Exceptions

The Task was disposed.

Remarks

This operation will return false if the Task<TResult> is already in one of the three final states: RanToCompletion, Faulted, or Canceled.

This method also returns false if the underlying Task<TResult> has already been disposed.

See also

Applies to

TrySetCanceled(CancellationToken)

Source:
TaskCompletionSource_T.cs
Source:
TaskCompletionSource_T.cs
Source:
TaskCompletionSource_T.cs

Attempts to transition the underlying Task<TResult> into the Canceled state and enables a cancellation token to be stored in the canceled task.

public:
 bool TrySetCanceled(System::Threading::CancellationToken cancellationToken);
public bool TrySetCanceled (System.Threading.CancellationToken cancellationToken);
member this.TrySetCanceled : System.Threading.CancellationToken -> bool
Public Function TrySetCanceled (cancellationToken As CancellationToken) As Boolean

Parameters

cancellationToken
CancellationToken

A cancellation token.

Returns

true if the operation is successful; otherwise, false.

Remarks

The method returns false if the underlying Task<TResult> object is already in one of the following three final states.

This method also returns false if the underlying Task<TResult> object has already been disposed.

Applies to