CPU friendly infinite loop

前端 未结 11 1919
心在旅途
心在旅途 2020-12-04 09:15

Writing an infinite loop is simple:

while(true){
    //add whatever break condition here
}

But this will trash the CPU performance. This ex

11条回答
  •  天命终不由人
    2020-12-04 09:42

    To keep console applications running just add a Console.ReadLine() to the end of your code in Main().

    If the user shouldn't be able to terminate the application you can do this with a loop like the following:

    while (true){
       Console.ReadLine();
    }
    

提交回复
热议问题