C# Thread.Sleep(1000) takes much more than 1000ms on some pc

后端 未结 2 1846
终归单人心
终归单人心 2021-01-28 12:19

I write a c# program to count down 5 seconds. What I do is:

        new Task(() =>
        {

                try
                {
                        th         


        
2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-28 13:02

    Sleep will wait at least that long before activating the thread again, but it can always be longer than that. After the one second time has passed the thread becomes eligible to execute by the CPU scheduler, and the scheduler is able to run it whenever it wants to. If it's particularly busy, and/or is using a scheduling algorithm that doesn't focus on quickly allowing newly active threads to run, it could be some time.

提交回复
热议问题