超まとめ
ループ処理しつつ処理をブロックせずにキー入力を受け付けるには、Console.KeyAvailable を使えばOK。
using System;
using System.Threading.Tasks;
namespace KeyInterruptHandling
{
class Program
{
static void Main(string[] args)
{
var outChar = "-";
//処理ループ
while (true)
{
Console.Write(outChar); //これがメインの処理に該当
//キー入力チェック。Eが入力されたらプログラム終了。
if(Console.KeyAvailable){
outChar = Console.ReadKey().Key.ToString();
if(outChar == "E"){
return;
}
}
}
}
}
}
Console.KeyAvailable は処理をブロックしないので、それでキー入力のありなしをチェック。
キー入力がある場合はReadKeyして入力されたキーを読み取る…という流れです。
補足
.NET Core 2.0.0で確認しました。