diff --git a/JetKarmaBot/Program.cs b/JetKarmaBot/Program.cs index ed77599..2438505 100644 --- a/JetKarmaBot/Program.cs +++ b/JetKarmaBot/Program.cs @@ -1,4 +1,6 @@ using System; +using System.Reflection; +using System.Runtime.Loader; using System.Threading; using JetKarmaBot.Models; using Microsoft.EntityFrameworkCore; @@ -57,6 +59,11 @@ namespace JetKarmaBot eArgs.Cancel = true; quitEvent.Set(); }; + AppDomain.CurrentDomain.ProcessExit += (sender, args) => + { + log.Info("Received stop request, waiting for exit..."); + bot?.Stop()?.Wait(); + }; } catch { }