Problem

Solution

Listing

Perform actions concurrently.

Concurrently iterate over a series of integer values.

Use the Parallel.Invoke() method. Use the Parallel.For() method.

5-1 and

Concurrently process a series of items in an array or collection.

Use the Parallel.ForEach() method.

Iterate over a series of stepped integer values.

Use the yield keyword to create a custom 5-5

IEnumerable<> that produced stepped integer results. Use with the Parallel.ForEach() method.

Limit concurrency for parallel loops or specify a custom task scheduler.

Create an instance of ParallelOptions, set the 5-6

appropriate properties, and pass it as an argument to Parallel.For() orParallel.ForEach().

Break out of a parallel loop.

Create an instance of ParallelLoopState, pass it as an 5-7 and argument to Parallel.For() or Parallel.ForEach(), 5-8 and call either the Break() or Stop() methods.

Check loop status.

Check the properties of the ParallelLoopResult instance returned as the result from the Parallel.For() and Parallel.ForEach() methods.

Cancel a parallel loop.

Create an instance of ParallelOptions, and set the CacellationToken property. Pass the options as an argument to Parallel.For() or Parallel.ForEach(), and cancel the token.

5-10

0 0

Post a comment