so in my program I want the first thread that finishes first's value to be displayed in console and then have it so that all remaining threads are then aborted. Here is the code that I have now that demonstrates the issue.
public static void test()
{
int Loop = 0;
Parallel.For(0, 2000, new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount }, (i, End) =>
{
Loop++;
Console.WriteLine(Loop);
if (Loop == 1000)
{
Console.WriteLine("Break!");
End.Break();
}
});
}
And when it's done here is a snippet of what gets outputted into the console
985
987
983
Break!
Break!
992
998
Break!
Break!
00:00:00.7217394
So right now I have no idea how to get it to stop all together when one thread matches the if statement. Any help would be greatly appreciated!