private bool Start = true;
static void Main()
{
Thread key = new Thread(Key);
key.Start();
int i = 0;
while(Start)
{
i++;
Console.WriteLine(i);
}
}
public static void Key()
{
ConsoleKeyInfo key = Console.ReadKey();
if (key.Key == ConsoleKey.Escape)
Start = false;
}