genielabs / HomeGenie

HomeGenie, the programmable automation intelligence
https://homegenie.it
GNU General Public License v3.0
387 stars 154 forks source link

Fix multiple instance of a program running .net core #437

Closed mtudury closed 3 years ago

mtudury commented 3 years ago

Hello,

I found that .NET core does not support Thread.Abort(), that was used to stop a program before compilation (CSharpEngine).

Resulting in multiple instance of same program continue to run on different thread.

After some extended tests with this simple program :

// CSharp Automation Program Plugin
// Example for using Helper Classes:
// Modules.WithName("Light 1").On();
var rand = new Random();
string unique_id = rand.Next(1024).ToString();

while (Program.IsRunning) {
  Pause(15);
  Program.Notify("test_multiple", unique_id);
}

Compiled multiple times gave me lots of "test_multiple", with different values within 15 seconds.

After some digging i found that Thread.Abort() throws exception : System.PlatformNotSupportedException: Thread abort is not supported on this platform.

Here's the fix i applied on my branch, i hope it can help.

Thanks

Matthieu