TaskCompletionSource<TResult>.TrySetCanceled Method
In this article
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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. |
- 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
.NET 10 and other versions
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
- 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
.NET 10 and other versions
Product | Versions |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10 |
.NET Framework | 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: