Task.IsCanceled 属性

定义

获取此 Task 实例是否由于被取消的原因而已完成执行。Gets whether this Task instance has completed execution due to being canceled.

public:
 property bool IsCanceled { bool get(); };
public bool IsCanceled { get; }
member this.IsCanceled : bool
Public ReadOnly Property IsCanceled As Boolean

属性值

Boolean

如果任务由于被取消而完成,则为 true;否则为 falsetrue if the task has completed due to being canceled; otherwise false.

注解

Task 以下任何条件下,都将在状态中完成 CanceledA Task will complete in the Canceled state under any of the following conditions:

重要

检索属性的值不 IsCanceled 会阻止调用线程,直到任务完成。Retrieving the value of the IsCanceled property does not block the calling thread until the task has completed.

适用于