Manually Implementing a Parallel.For Loop

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.