Skip to content

Instantly share code, notes, and snippets.

View ehsan-davoudi's full-sized avatar

Ehsan Davoudi ehsan-davoudi

View GitHub Profile
@ehsan-davoudi
ehsan-davoudi / gist:8688427
Created January 29, 2014 13:54
Run List of Tasks Asynchronously with async/await in C#
Assume we have a list of tasks and we need to run them asynchronously, we can use below code:
var toDoTasks = new List<OurTask>();
IEnumerable<Task<int>> taskListQuery = from toDoTask in toDoTasks select DoSomething(ourTask);
List<Task<int>> taskList = taskListQuery.ToList();
while (taskList.Count > 0)
{
Task<int> firstFinishedTask = await Task.WhenAny(taskList);