ParallelLoopState::LowestBreakIteration Property
Gets the lowest iteration of the loop from which Break was called.
Assembly: mscorlib (in mscorlib.dll)
Property Value
Type: System::Nullable<Int64>The lowest iteration from which Break was called. In the case of a Parallel::ForEach<TSource> loop, the value is based on an internally-generated index.
It is possible for multiple iterations of a parallel loop to call the Break method. If they do, this value is the smallest index of an iteration that called Break. If no iteration of the loop called Break, this property returns null. Note that the property value is unaffected by calls to the Stop method.
In long-running iterations in which all iterations after the iteration that calls the Break method need not run, the LowestBreakIteration property is used to terminate iterations that began execution before the call to the Break method. To stop iterations whose index is greater than the lowest break iteration from competing execution, you should do the following:
Check whether the ShouldExitCurrentIteration property is true.
Exit from the iteration if its index is greater than the LowestBreakIteration property value.
The example provides an illustration.
The following example executes up to 100 iterations of a loop in parallel. Each iteration pauses for a random interval from 1 to 1,000 milliseconds. A randomly generated value determines on which iteration of the loop the Break method is called. This prevents iterations whose index is greater than the LowestBreakIteration property value from starting after the call to the Break method, but it does not affect any iterations that have already begun executing. To prevent these from completing, each iteration calls the ShouldExitCurrentIteration method to check whether another iteration has called the Break method. If so, the iteration checks the value of the LowestBreakIteration property and, if it is greater than the current iteration's index value, returns immediately.
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Windows Phone
Available since 8.1
Note that, because the LowestBreakIteration value is out of scope outside of the parallel loop, you must assign it to a variable that is visible outside of the loop if you want to preserve its value.