If using netcore you dont need mono
This commit is contained in:
parent
a13e03a808
commit
ec93004c2b
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.Loader;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Bots {
|
namespace BlubbFish.Utils.IoT.Bots {
|
||||||
@ -8,14 +9,22 @@ namespace BlubbFish.Utils.IoT.Bots {
|
|||||||
|
|
||||||
protected ProgramLogger logger = new ProgramLogger();
|
protected ProgramLogger logger = new ProgramLogger();
|
||||||
|
|
||||||
|
#if !NETCOREAPP
|
||||||
private void SetupShutdown(Object sender, ConsoleCancelEventArgs e) {
|
private void SetupShutdown(Object sender, ConsoleCancelEventArgs e) {
|
||||||
e.Cancel = true;
|
e.Cancel = true;
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.SetupShutdown: Signalhandler Windows INT recieved.");
|
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.SetupShutdown: Signalhandler Windows INT recieved.");
|
||||||
this.RunningProcess = false;
|
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() {
|
protected void WaitForShutdown() {
|
||||||
if(Type.GetType("Mono.Runtime") != null) {
|
if(Type.GetType("Mono.Runtime") != null) {
|
||||||
|
#if !NETCOREAPP
|
||||||
this.sig_thread = new Thread(delegate () {
|
this.sig_thread = new Thread(delegate () {
|
||||||
Mono.Unix.UnixSignal[] signals = new Mono.Unix.UnixSignal[] {
|
Mono.Unix.UnixSignal[] signals = new Mono.Unix.UnixSignal[] {
|
||||||
new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGTERM),
|
new Mono.Unix.UnixSignal(Mono.Unix.Native.Signum.SIGTERM),
|
||||||
@ -30,15 +39,22 @@ namespace BlubbFish.Utils.IoT.Bots {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.sig_thread.Start();
|
this.sig_thread.Start();
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
|
#if NETCOREAPP
|
||||||
|
AssemblyLoadContext.Default.Unloading += this.Default_Unloading;
|
||||||
|
#else
|
||||||
Console.CancelKeyPress += new ConsoleCancelEventHandler(this.SetupShutdown);
|
Console.CancelKeyPress += new ConsoleCancelEventHandler(this.SetupShutdown);
|
||||||
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.WaitForShutdown: Signalhandler Windows attached.");
|
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.WaitForShutdown: Signalhandler Windows attached.");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
while(this.RunningProcess) {
|
while(this.RunningProcess) {
|
||||||
Thread.Sleep(100);
|
Thread.Sleep(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public virtual void Dispose() {
|
public virtual void Dispose() {
|
||||||
if(this.sig_thread != null && this.sig_thread.IsAlive) {
|
if(this.sig_thread != null && this.sig_thread.IsAlive) {
|
||||||
this.sig_thread.Abort();
|
this.sig_thread.Abort();
|
||||||
|
Loading…
Reference in New Issue
Block a user