完成多种方法后,我需要生成报告。但在此示例中,它们不是异步的。
static void Main(string[] args)
{
TaskMan();
}
async static void TaskMan()
{
Task t1 = m1();
Task t2 = m2();
await Task.WhenAll(t1, t2);
Console.WriteLine("Complete");
}
async static Task m1()
{
decimal result = 0;
for (int n = 1; n < 100000000; n++)
{
result += n;
}
Console.WriteLine(result);
}
async static Task m2()
{
decimal result = 0;
for (int n = 1; n < 100000000; n++)
{
result += n;
}
Console.WriteLine(result);
}
如何让它们真正异步?