Console ReadKey timeout
c#
Solution
I would do it like this:
DateTime beginWait = DateTime.Now;
while (!Console.KeyAvailable && DateTime.Now.Subtract(beginWait).TotalSeconds < 5)
Thread.Sleep(250);
if (!Console.KeyAvailable)
Console.WriteLine("You didn't press anything!");
else
Console.WriteLine("You pressed: {0}", Console.ReadKey().KeyChar);
Problem
I have built a simple console application, and I need to give a specific time for user to input a keychar. Should I use this? ``` System.Threading.Thread.Sleep(1000); ``` For those who didn't understand, I need the program to skip the `Console.ReadKey().KeyChar;` after `x` seconds. Is this possible?