How to interrupt Console.ReadLine

后端 未结 10 810
情歌与酒
情歌与酒 2020-11-28 11:34

Is it possible to stop the Console.ReadLine() programmatically?

I have a console application: the much of the logic runs on a different thread and in th

10条回答
  •  悲&欢浪女
    2020-11-28 11:43

    This will process a Ctrl+C in a seperate thread while your app is waiting for a Console.Readline():

    Console.CancelKeyPress += (_, e) =>
    {
        e.Cancel = true;
        Environment.Exit(0);
    };
    

提交回复
热议问题