Export (0) Print
Expand All

ParallelLoopState.Break Method

Communicates that the Parallel loop should cease execution at the system's earliest convenience of iterations beyond the current iteration.

Namespace:  System.Threading.Tasks
Assembly:  mscorlib (in mscorlib.dll)

public void Break()

ExceptionCondition
InvalidOperationException

The Stop method was previously called. Break and Stop may not be used in combination by iterations of the same loop.

Break may be used to communicate to the loop that no other iterations after the current iteration need be run. For example, if Break is called from the 100th iteration of a for loop iterating in parallel from 0 to 1000, all iterations less than 100 should still be run, but the iterations from 101 through to 1000 are not necessary.

For long-running iterations that may already be executing, Break causes LowestBreakIteration to be set to the current iteration's index if the current index is less than the current value of LowestBreakIteration.

Break is typically employed in search-based algorithms where an ordering is present in the data source.

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1
Show:
© 2015 Microsoft