Running Multiple Tasks
Create multiple tasks and add the task objects to an array or collection. Later loop through the tasks and access the result.
public static void Main()
{
Task<Double>[] taskArray = {
Task<Double>.Run(() => DoComputation(1)),
Task<Double>.Run(() => DoComputation(100)),
Task<Double>.Run(() => DoComputation(1000)),
};
for(int i = 0; i < taskArray.Length; i++)
{
Console.WriteLine("{0:N2}", taskArray[i].Result);
}
}
private static Double DoComputation(Double start)
{
Double sum = 0;
for (var value = start; value <= start + 10; value += .1)
sum += value;
return sum;
}