Task.IsCanceled 属性
定义
public:
property bool IsCanceled { bool get(); };
public bool IsCanceled { get; }
member this.IsCanceled : bool
Public ReadOnly Property IsCanceled As Boolean
属性值
如果任务由于被取消而完成,则为 true;否则为 false。true if the task has completed due to being canceled; otherwise false.
注解
在 Task 以下任何条件下,都将在状态中完成 Canceled :A Task will complete in the Canceled state under any of the following conditions:
CancellationToken在任务开始执行之前,已将其标记为取消。Its CancellationToken was marked for cancellation before the task started executing,
该任务 CancellationToken 通过引发具有相同的的发出的,确认了取消请求 OperationCanceledException CancellationToken 。The task acknowledged the cancellation request on its already signaled CancellationToken by throwing an OperationCanceledException that bears the same CancellationToken.
该任务 CancellationToken 通过调用上的方法,确认了对它已发出信号的取消请求 ThrowIfCancellationRequested CancellationToken 。The task acknowledged the cancellation request on its already signaled CancellationToken by calling the ThrowIfCancellationRequested method on the CancellationToken.
重要
检索属性的值不 IsCanceled 会阻止调用线程,直到任务完成。Retrieving the value of the IsCanceled property does not block the calling thread until the task has completed.