问题 This question already has answers here : Closed 6 years ago . Possible Duplicate: How to add a Timeout to Console.ReadLine()? If I have a Console.ReadKey(), It makes the whole program stuck, how can I make it so that it will read a key for 1 second, and if a key is not read, something else would be set. 回答1: static ConsoleKeyInfo? MyReadKey() { var task = Task.Run(() => Console.ReadKey(true)); bool read = task.Wait(1000); if (read) return task.Result; return null; } var key = MyReadKey(); if