相关疑难解决方法(0)

为什么Thread.Sleep会影响新任务的创建?

private static void Main(string[] args)
{
    for (int i = 0; i < 1000; i++)
    {
        Task.Factory.StartNew(() =>
        {
            Thread.Sleep(1000);
            Console.WriteLine("hej");
            Thread.Sleep(10000);
        });    
    }
    Console.ReadLine();
}
Run Code Online (Sandbox Code Playgroud)

为什么这段代码在一秒钟后不能打印1000次"hej"?为什么Thread.Sleep(10000)会对代码行为产生影响?

c# multithreading task threadpool

4
推荐指数
1
解决办法
575
查看次数

标签 统计

c# ×1

multithreading ×1

task ×1

threadpool ×1