Wait for ctrl-c before exiting

This commit is contained in:
Laura Hausmann 2023-01-20 18:59:26 +01:00
parent faa36441aa
commit 627eaac647
Signed by: zotan
GPG key ID: D044E84C5BE01605

View file

@ -33,7 +33,13 @@ var iBotCommands = new List<string> {
bot.StartReceiving(HandleUpdateAsync, PollingErrorHandler, null, cts.Token);
Console.WriteLine($"Start listening for @{me.Username}");
do { } while (Console.ReadLine() != "exit");
var exitEvent = new ManualResetEvent(false);
Console.CancelKeyPress += (sender, eventArgs) => {
eventArgs.Cancel = true;
exitEvent.Set();
};
exitEvent.WaitOne();
cts.Cancel();