I have a problem with the following code:
using System; class Yellow { static void Main() { Console.WriteLine("Check_1"); Console.ReadKey(); Console.WriteLine("Check_2"); char beep = '\a'; int i = 3; while (!Console.KeyAvailable) { Console.WriteLine(beep); System.Threading.Thread.Sleep(200); Console.WriteLine("Check_" + i); i++; } } }
After waiting for the input character to be entered, this program generates a sound signal and a Check_<i>
message with an expectation of 200 milliseconds between each cycle. If you press the key during this cycle, the program will end.
However, when I wait for the loop to work many times (about 36 times), the loop does not interrupt when I press the key. When I try to manually close the console using the X
button, the program does not respond.
Why does it matter if the cycle has been run several dozen times?
source share