You need to use a cancellation token:
var
cancelToken: IOmniCancellationToken;
You obtain the cancellation token by calling CreateOmniCancellationToken
from the OtlSync
unit.
cancelToken := CreateOmniCancellationToken;
You then supply the token to the parallel loop:
Parallel.ForEach(...)
.CancelWith(cancelToken)
.Execute(...);
And you signal the cancellation token by calling its Signal
method.
cancelToken.Signal;
From outside the parallel loop you can use
cancelToken.IsSignaled
to detect that you cancelled. Or you can capture a boolean variable from the surrounding scope and pass the information through that variable.
The example here gives an illustration.