.NET Thread.Sleep() is randomly imprecise

前端 未结 7 1973
故里飘歌
故里飘歌 2021-01-20 01:34

In my .NET application I have to replay a series of sensor events. So I created a thread that fires these events (usually about every 1 - 4 millisecond). I implemented a loo

7条回答
  •  难免孤独
    2021-01-20 02:16

    Thread.Sleep only guarantees that the thread will sleep for at least the specified interval. It does not give accuracy guarantees -- indeed it cannot do so, because it is the OS scheduler that decides when each blocked thread should be given CPU time.

    If threads could demand that they be run again in a specific point in time then preemptive multitasking would be impossible.

提交回复
热议问题