我需要在同一时间异步运行一组繁重的函数,并将结果填充到列表中。下面是这个伪代码:我需要foreach
博克内部的逻辑如何并行运行一组函数并在完成后等待结果?
List<TResult> results = new List<TResults>();
List<Func<T, TResult>> tasks = PopulateTasks();
foreach(var task in tasks)
{
// Run Logic in question
1. Run each task asynchronously/parallely
2. Put the results in the results list upon each task completion
}
Console.WriteLine("All tasks completed and results populated");
。你们可以帮我吗?
我有一些约束:该解决方案必须在.NET 3.5兼容的(不是.NET 4,但.NET 4替代解决方案将不胜感激我的知识的目的)提前
感谢。
另见http://stackoverflow.com/questions/11564506/nesting-await-in-parallel-foreach(我的回答是http://stackoverflow.com/a/25877042/67824) – 2014-10-14 12:43:57