c# 并行循环支持 async

var bag = new ConcurrentBag<object>();
var tasks = myCollection.Select(async item =>
{
  // some pre stuff
  var response = await GetData(item);
  bag.Add(response);
  // some post stuff
});
await Task.WhenAll(tasks);
var count = bag.Count;

 

posted @ 2019-08-22 09:14  小小高  阅读(492)  评论(0编辑  收藏  举报