Skip to content

Instantly share code, notes, and snippets.

@M-Yankov
Created October 27, 2017 13:58
Show Gist options
  • Save M-Yankov/945d7052b80870335f7e2165e65a13f7 to your computer and use it in GitHub Desktop.
Save M-Yankov/945d7052b80870335f7e2165e65a13f7 to your computer and use it in GitHub Desktop.
How to execute something asynchronous
var taskArray = new Task[tasksCount];
for (int index = 0; index < taskArray.Length; index++)
{
var productId = productIds[index];
var task = Task.Run(() => UpdatePoductStatus(productId, Status.Available));
taskArray[index] = task;
}
Task.WaitAll(taskArray);
// UpdatePoductStatus is a method declared somewhere in the code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment