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

前端 未结 6 844
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:13

    I think the call

    while (true) { ... } 
    

    is computationally intensive, since the thread never stops, wheareas

    Thread.Sleep(Timeout.Infinite);
    

    actually gets the thread to sleep with help of OS native schedulers. And then the thread actually stops, so I suppose it's less computationally demanding.

提交回复
热议问题