If you want to be able to use the kill switch to cancel a running C# script at runtime, you may need to manually place the possible cancellation stops in your script.
To start, every Chat message creation checks for an ongoing cancellation by default. Further, if you need to be able to cancel long running loops, use the following method if no Chat message will be created during the loop:
Script.CancellationCheck();
C#
This allows you to kill a running C# script Task in a well-behaved and traceable way:
Here's how manual cancellation was used in this example:
using System.Threading;
Console.WriteLine("Long running loop has started");
for (int i = 0; i < 100; i++)
{
Script.CancellationCheck();
Thread.Sleep(2000);
}
C#