简体   繁体   中英

Executing Tasks in Parallel - Silverlight

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;
        }

"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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM