From 3b5a07aab3cd63efcaa67c7fed808bb2a3f6077d Mon Sep 17 00:00:00 2001 From: Archi Date: Mon, 1 Nov 2021 18:55:58 +0100 Subject: [PATCH] React appropriate to SIGINT (CTRL+C) We're using custom console mechanism in order to implement interactive console, on top of that CTRL+C would not work when using IPC: true due to the fact that it doesn't trigger shutdown sequence, fix both of those problems by listening to SIGINT and exiting with code 130 upon receiving one Tested on Linux --- ArchiSteamFarm/Program.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ArchiSteamFarm/Program.cs b/ArchiSteamFarm/Program.cs index 67cd05d14..267598736 100644 --- a/ArchiSteamFarm/Program.cs +++ b/ArchiSteamFarm/Program.cs @@ -125,6 +125,8 @@ namespace ArchiSteamFarm { AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; TaskScheduler.UnobservedTaskException += OnUnobservedTaskException; + Console.CancelKeyPress += OnCancelKeyPress; + // Add support for custom encodings Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); @@ -396,6 +398,8 @@ namespace ArchiSteamFarm { return await ShutdownResetEvent.Task.ConfigureAwait(false); } + private static async void OnCancelKeyPress(object? sender, ConsoleCancelEventArgs e) => await Exit(130).ConfigureAwait(false); + private static async void OnProcessExit(object? sender, EventArgs e) => await Shutdown().ConfigureAwait(false); private static async void OnUnhandledException(object? sender, UnhandledExceptionEventArgs e) {