System.Threading.Parallel.ParallelFor Class

public sealed class ParallelFor: ParallelLoop<int>

Base Types

System.Threading.Parallel.ParallelLoop<int>
  ParallelFor

Assembly

System.Threading.Parallel

Library

Parallel

Summary

A parallel loop over consecutive integers, starting at 0

Description

[Note: ParallelFor provides basic parallelism over an index space known in advance. The index space is 0..(N-1) for some value of N. This is the common case in -for- loops, and one can easily derive more complex arithmetic sequences via linear transformation of the index variable.]

See Also

System.Threading.Parallel Namespace

Members

ParallelFor Constructors

ParallelFor(int) Constructor
ParallelFor(int, int) Constructor

ParallelFor Methods

ParallelFor.BeginRun Method
ParallelFor.Cancel Method


ParallelFor(int) Constructor

public ParallelFor(int count);

Summary

Constructs a ParallelFor that will iterate over the integers 0..count-1.

Parameters

count
number of loop iterations

Description

The loop starts executing when method System.Threading.Parallel.ParallelFor.BeginRun is called.

See Also

System.Threading.Parallel.ParallelFor Class, System.Threading.Parallel Namespace

ParallelFor(int, int) Constructor

public ParallelFor(int count, int numThreads);

Summary

Constructs a ParallelFor that will iterate over the integers 0..count-1.

Parameters

count
number of loop iterations
numThreads
maximum number of threads to use

Exceptions

Exception TypeCondition
ArgumentExceptionThe value for numThreads is negative

Description

The loop starts executing when method System.Threading.Parallel.ParallelFor.BeginRun is called.

If numThreads is 0, then up to System.Threading.Parallel.ParallelEnvironment.MaxThreads threads are used instead. The value of numThreads includes the thread that created the System.Threading.Parallel.ParallelFor<T>, hence using numThreads=1 forces sequential execution.

See Also

System.Threading.Parallel.ParallelFor Class, System.Threading.Parallel Namespace

ParallelFor.BeginRun Method

public override void BeginRun(Action<T> action);

Summary

Begin executing iterations.

Parameters

action
The Delegate that processes each work item.

Exceptions

Exception TypeCondition
ArgumentNullExceptionaction is null .

Description

This method is not thread safe. It should be called only once for a given instance of a ParallelFor.

[Note: Implementations, particularly on single-threaded hardware, are free to employ the calling thread to execute all loop iterations.]

See Also

System.Threading.Parallel.ParallelFor Class, System.Threading.Parallel Namespace

ParallelFor.Cancel Method

public override void Cancel();

Summary

Cancel any iterations that have not yet started

Description

This method is safe to call concurrently on the same instance.

See Also

System.Threading.Parallel.ParallelFor Class, System.Threading.Parallel Namespace