Break Method

Task Parallel System.Threading

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:  System.Threading (in System.Threading.dll)

Syntax

Visual Basic (Declaration)
Public Sub Break
C#
public void Break()

Remarks

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.

Exceptions

ExceptionCondition
System..::.InvalidOperationException The Stop()()() method was previously called. Break()()() and Stop()()() may not be used in combination by iterations of the same loop.

See Also