Change signalhandling netcore
This commit is contained in:
parent
ec93004c2b
commit
9326ab8659
@ -4,23 +4,22 @@ using System.Threading;
|
|||||||
|
|
||||||
namespace BlubbFish.Utils.IoT.Bots {
|
namespace BlubbFish.Utils.IoT.Bots {
|
||||||
public abstract class ABot {
|
public abstract class ABot {
|
||||||
|
#if !NETCOREAPP
|
||||||
private Thread sig_thread;
|
private Thread sig_thread;
|
||||||
|
#endif
|
||||||
private Boolean RunningProcess = true;
|
private Boolean RunningProcess = true;
|
||||||
|
|
||||||
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) {
|
private void Default_Unloading(AssemblyLoadContext obj) {
|
||||||
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;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
protected void WaitForShutdown() {
|
protected void WaitForShutdown() {
|
||||||
if(Type.GetType("Mono.Runtime") != null) {
|
if(Type.GetType("Mono.Runtime") != null) {
|
||||||
@ -41,12 +40,10 @@ namespace BlubbFish.Utils.IoT.Bots {
|
|||||||
this.sig_thread.Start();
|
this.sig_thread.Start();
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
#if NETCOREAPP
|
|
||||||
AssemblyLoadContext.Default.Unloading += this.Default_Unloading;
|
AssemblyLoadContext.Default.Unloading += this.Default_Unloading;
|
||||||
#else
|
Console.WriteLine("BlubbFish.Utils.IoT.Bots.Bot.WaitForShutdown: Signalhandler Netcore attached.");
|
||||||
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);
|
||||||
@ -56,9 +53,11 @@ namespace BlubbFish.Utils.IoT.Bots {
|
|||||||
|
|
||||||
|
|
||||||
public virtual void Dispose() {
|
public virtual void Dispose() {
|
||||||
|
#if !NETCOREAPP
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#if NETCOREAPP
|
#if !NETCOREAPP
|
||||||
#else
|
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Resources;
|
using System.Resources;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
@ -37,7 +36,7 @@ using System.Runtime.InteropServices;
|
|||||||
// [assembly: AssemblyVersion("1.0.*")]
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
[assembly: AssemblyVersion("1.2.1")]
|
[assembly: AssemblyVersion("1.2.1")]
|
||||||
[assembly: AssemblyFileVersion("1.2.1")]
|
[assembly: AssemblyFileVersion("1.2.1")]
|
||||||
|
#endif
|
||||||
/*
|
/*
|
||||||
* 1.1.0 Remove Helper from Bot-Utils
|
* 1.1.0 Remove Helper from Bot-Utils
|
||||||
* 1.1.1 Update to local librarys
|
* 1.1.1 Update to local librarys
|
||||||
@ -53,4 +52,3 @@ using System.Runtime.InteropServices;
|
|||||||
* 1.2.0 Refactor Bot to ABot and refere MultiSourceBot, Webserver and Bot to it. Add MultiSourceBot. Rewrite Mqtt module so that it not need to watch the connection.
|
* 1.2.0 Refactor Bot to ABot and refere MultiSourceBot, Webserver and Bot to it. Add MultiSourceBot. Rewrite Mqtt module so that it not need to watch the connection.
|
||||||
* 1.2.1 When using Dispose, kill also mqtt connection and other tiny fixes
|
* 1.2.1 When using Dispose, kill also mqtt connection and other tiny fixes
|
||||||
*/
|
*/
|
||||||
#endif
|
|
Loading…
Reference in New Issue
Block a user