If using netcore you dont need mono

This commit is contained in:
BlubbFish 2019-11-26 18:33:58 +01:00
parent a13e03a808
commit ec93004c2b

View File

@ -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();