How do I break out of an parallel.for loop?
I have a pretty complex statement which looks like the following:
Parallel.ForEach
Use the ParallelLoopState.Break method:
Parallel.ForEach(list,
(i, state) =>
{
state.Break();
});
Or in your case:
Parallel.ForEach(ColorIndex.AsEnumerable(),
new Action((ColorIndexHolder Element, ParallelLoopState state) =>
{
if (Element.StartIndex <= I && Element.StartIndex + Element.Length >= I)
{
Found = true;
state.Break();
}
}));