Is Thread.Sleep(Timeout.Infinite); more efficient than while(true){}?

前端 未结 6 830
Happy的楠姐
Happy的楠姐 2020-12-09 02:46

I have a console application that I would like to keep open all of the time while still listening in to events. I have tested Thread.Sleep(Timeout.Infinite); an

6条回答
  •  时光说笑
    2020-12-09 03:27

    Calling the Thread.Sleep method causes the current thread to immediately block for the number of milliseconds or the time interval you pass to the method, and yields the remainder of its time slice to another thread.

    https://docs.microsoft.com/en-us/dotnet/standard/threading/pausing-and-resuming-threads?redirectedfrom=MSDN#the-threadsleep-method

提交回复
热议问题