C#线程睡眠和并行

时间:2018-06-02 07:57:55

标签: c# asynchronous concurrency

关于以下代码示例,为什么Thread.Sleep使代码按顺序运行,但是如果我删除该行并行运行?

private static void Main(string[] args) => UsageParallel();
public static void UsageParallel()      => MainParallel().Wait();
public static async Task MainParallel() => await Task.WhenAll(Named(), Named());

public static async Task Named()
{
    Console.WriteLine("named start");
    await Task.Delay(2000);
    Thread.Sleep(2000);
    Console.WriteLine("named end");
}

0 个答案:

没有答案