Use Console.KeyAvailable
so that you only call ReadKey
when you know it won’t block:
Console.WriteLine("Press ESC to stop");
do {
while (! Console.KeyAvailable) {
// Do something
}
} while (Console.ReadKey(true).Key != ConsoleKey.Escape);
More Related Contents:
- Opening a text file is passed as a command line parameter [closed]
- Cannot Implicitly Convert int to int[] [closed]
- C# – variable not setting from another class
- Why does this nested loop output starts at 8 and 18?
- How can I get the application’s path in a .NET console application?
- How to write Unicode characters to the console?
- How do I show a console output/window in a forms application?
- Could not load file or assembly … An attempt was made to load a program with an incorrect format (System.BadImageFormatException)
- .NET console application as Windows service
- Custom text color in C# console application?
- .NET Global exception handler in console application
- Global hotkey in console application
- Displaying Arabic characters in C# console application
- How to programmatic disable C# Console Application’s Quick Edit mode?
- Command to close an application of console?
- Why the default SynchronizationContext is not captured in a Console App?
- How to keep console window open
- Console App Mouse-Click X Y Coordinate Detection/Comparison
- What is the command to exit a console application in C#?
- C# console application icon
- How to fix “No overload for method ‘ ‘ takes 0 arguments”?
- Password masking console application
- How to navigate a few folders up?
- Non-Blocking read from standard I/O in C# [closed]
- Compile to a stand-alone executable (.exe) in Visual Studio
- How do I get a return value from Task.WaitAll() in a console app?
- Changing font in a Console window in .NET
- Is it possible to send Toast notification from console application?
- how to handle spaces in file path if the folder contains the space?
- CPU friendly infinite loop