Manually Implementing a Parallel.For Loop

January 12, 2017

Why would you do this?

PCLs don’t support them

Okay - How?



List<Task> myTasks = new List<Task>();

for (int i = 1; i <= 10; i++) // Artificially implement Parallel.For because this is a PCL
{
    myTasks.Add(Task.Run(() =>
    {
        // Task logic goes here
    }));
}

await Task.WhenAll(myTasks);


Small victories.



Profile picture

A blog about one man's journey through code… and some pictures of the Peak District
Twitter

© Paul Michaels 2024