diff --git a/Bot-Utils/ABot.cs b/Bot-Utils/ABot.cs index 86da32b..76ba4b9 100644 --- a/Bot-Utils/ABot.cs +++ b/Bot-Utils/ABot.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.Loader; using System.Threading; namespace BlubbFish.Utils.IoT.Bots { @@ -8,14 +9,22 @@ namespace BlubbFish.Utils.IoT.Bots { protected ProgramLogger logger = new ProgramLogger(); + #if !NETCOREAPP private void SetupShutdown(Object sender, ConsoleCancelEventArgs e) { e.Cancel = true; Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.SetupShutdown: Signalhandler Windows INT recieved."); this.RunningProcess = false; } + #else + private void Default_Unloading(AssemblyLoadContext obj) { + Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.SetupShutdown: Signalhandler Windows INT recieved."); + this.RunningProcess = false; + } + #endif protected void WaitForShutdown() { - if(Type.GetType("Mono.Runtime") != null) { + if(Type.GetType("Mono.Runtime") != null) { + #if !NETCOREAPP this.sig_thread = new Thread(delegate () { Mono.Unix.UnixSignal[] signals = new Mono.Unix.UnixSignal[] { new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGTERM), @@ -30,15 +39,22 @@ namespace BlubbFish.Utils.IoT.Bots { } }); this.sig_thread.Start(); - } else { + #endif + } else { + #if NETCOREAPP + AssemblyLoadContext.Default.Unloading += this.Default_Unloading; + #else Console.CancelKeyPress += new ConsoleCancelEventHandler(this.SetupShutdown); Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.WaitForShutdown: Signalhandler Windows attached."); + #endif } while(this.RunningProcess) { Thread.Sleep(100); } } + + public virtual void Dispose() { if(this.sig_thread != null && this.sig_thread.IsAlive) { this.sig_thread.Abort();