Reputation: 7692
I want to start a bunch of tasks and wait for all of them to finish.
This question is more or less identical to this question: Executing tasks in parallel
But, the answer is not same for Silverlight because there is no equivalent method to Task.WhenAll().
This should work, but I get an error
Start may not be called on a promise-style task.
foreach (var displayThumbnailTask in displayThumbnailTasks)
{
displayThumbnailTask.Start();
}
foreach (var task in displayThumbnailTasks)
{
await task;
}
Upvotes: 2
Views: 329
Reputation: 3147
"Start may not be called on a promise-style task." is a somewhat misleading message for the simple thing: the task has already been started.
Thus, you may just omit the first loop.
Silverlight does not have Task.WhenAll
, but if you are using Microsoft.Bcl.Async
, it contains TaskEx.WhenAll
which is the same.
await TaskEx.WhenAll(displayThumbnailTasks);
Execute parallel tasks with async/await
Upvotes: 3