ParallelEnumerable.WithCancellation<TSource>(ParallelQuery<TSource>, CancellationToken) 方法

定义

设置要与查询关联的 CancellationTokenSets the CancellationToken to associate with the query.

public:
generic <typename TSource>
[System::Runtime::CompilerServices::Extension]
 static System::Linq::ParallelQuery<TSource> ^ WithCancellation(System::Linq::ParallelQuery<TSource> ^ source, System::Threading::CancellationToken cancellationToken);
public static System.Linq.ParallelQuery<TSource> WithCancellation<TSource> (this System.Linq.ParallelQuery<TSource> source, System.Threading.CancellationToken cancellationToken);
static member WithCancellation : System.Linq.ParallelQuery<'Source> * System.Threading.CancellationToken -> System.Linq.ParallelQuery<'Source>

类型参数

TSource

source 的元素类型。The type of elements of source.

参数

source
ParallelQuery<TSource>

要对其设置选项的 ParallelQuery。A ParallelQuery on which to set the option.

cancellationToken
CancellationToken

取消标记。A cancellation token.

返回

表示与源相同的查询的 ParallelQuery,但带有已注册的取消标记。ParallelQuery representing the same query as source, but with the registered cancellation token.

例外

CancellationTokenSource 关联的 cancellationToken 已被释放。The CancellationTokenSource associated with the cancellationToken has been disposed.

source 为 null 引用(在 Visual Basic 中为 Nothing)。source is a null reference (Nothing in Visual Basic).

在该查询中,多次使用 WithCancellationWithCancellation is used multiple times in the query.

适用于

另请参阅