ParallelLoopState::ShouldExitCurrentIteration Property

.NET Framework (current version)
 

Gets whether the current iteration of the loop should exit based on requests made by this or other iterations.

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

public:
property bool ShouldExitCurrentIteration {
	bool get();
}

Property Value

Type: System::Boolean

true if the current iteration should exit; otherwise, false.

The ShouldExitCurrentIteration property is set to true under any of the following conditions:

  • An iteration of the loop calls Break or Stop.

  • An iteration of the loop throws an exception.

  • The loop is canceled.

When this property is true, the Parallel class will proactively attempt to prohibit additional iterations of the loop from starting execution. However, there may be cases where it is unable to prevent additional iterations from starting.

It may also be the case that a long-running iteration has already begun execution. In such cases, iterations may explicitly check the ShouldExitCurrentIteration property and cease execution if the property returns true.

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.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Windows Phone
Available since 8.1
Return to top
Show: