using Parallel.ForEach with/or async/await

こ雲淡風輕ζ 提交于 2019-12-05 20:50:43

You certainly don't want to use Parallel.ForEach. Parallel is for spreading CPU-bound algorithms over multiple cores, which would provide you no benefit (in your scenario, your algorithm is not CPU-bound).

What you actually want is concurrency, not parallelism. Asynchronous concurrency can be done using Task.WhenAll:

Dim tasks = myImages.Select(Function(x) testUrl_async(x))
Dim results = Await Task.WhenAll(tasks)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!