I want a non-blocking read function from console. How do I write that in C#?
Richard Dutton has a solution on his blog:
while (true)
{
if (Console.KeyAvailable)
{
ConsoleKeyInfo key = Console.ReadKey(true);
switch (key.Key)
{
case ConsoleKey.F1:
Console.WriteLine("You pressed F1!");
break;
default:
break;
}
}
// Do something more useful
}