ParallelEnumerable.WithCancellation<TSource> Method (ParallelQuery<TSource>, CancellationToken)

.NET Framework (current version)
 

Sets the CancellationToken to associate with the query.

Namespace:   System.Linq
Assembly:  System.Core (in System.Core.dll)

public static ParallelQuery<TSource> WithCancellation<TSource>(
	this ParallelQuery<TSource> source,
	CancellationToken cancellationToken
)

Parameters

source
Type: System.Linq.ParallelQuery<TSource>

A ParallelQuery on which to set the option.

cancellationToken
Type: System.Threading.CancellationToken

A cancellation token.

Return Value

Type: System.Linq.ParallelQuery<TSource>

ParallelQuery representing the same query as source, but with the registered cancellation token.

Type Parameters

TSource

The type of elements of source.

Exception Condition
ObjectDisposedException

The CancellationTokenSource associated with the cancellationToken has been disposed.

ArgumentNullException

source is a null reference (Nothing in Visual Basic).

InvalidOperationException

WithCancellation is used multiple times in the query.

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Windows Phone
Available since 8.1
Return to top
Show: