如何继续运行控制台应用程序,直到按键(如Esc被按下?)为止
我假设它包裹在while循环中。我不喜欢ReadKey
它阻止操作并要求输入按键,而不是继续听按键的声音。
如何才能做到这一点?
使用,Console.KeyAvailable
以便仅ReadKey
在您知道它不会阻止时呼叫:
Console.WriteLine("Press ESC to stop");
do {
while (! Console.KeyAvailable) {
// Do something
}
} while (Console.ReadKey(true).Key != ConsoleKey.Escape);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句