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;

 

转载于:https://www.cnblogs.com/gaocong/p/11392446.html

你可能感兴趣的:(c# 并行循环支持 async)