Thread.Sleep(0) doesn't work as described?

前端 未结 5 2006
清酒与你
清酒与你 2021-01-17 19:49

I am currently reading this excellent article on threading and read the following text:

Thread.Sleep(0) relinquishes the thread’s current time slice i

5条回答
  •  耶瑟儿~
    2021-01-17 20:18

    The next thread the processor handles is random thread and it even could be the same thread you just called Thread.Sleep(0). To ensure that next thread will be not the same thread you can call Thread.Yield() and check it's return result - if os has another thread that can run true will be returned else false.

提交回复
热议问题