Closed nooogle closed 3 years ago
Think we need to use cancellation tokens when running the actual script.
Yikes! So CSharpScript.RunAsync doesn't actually return until the script has completed! Using a cancellation token doesn't cancel a long running script.
From digging on Google it seems that no one can do this, at least not easily. The Visual Studio interactive C# script panel does allow a Reset, but it looks like the script runs in a separate process which is how it can be killed off; it also means a script run like this can't communicate with its host directly which is what I need from this library.
Rats.
It might be possible to run a script in a wrapper task, and then kill the task??
At the very least - add a demo form test to show how the global variables object can be used to provide a signal (even a simple bool QuitScript property would suffice)
Added AsyncRun to the script runner and AsyncGo to to the easy script utility; these just wrap their respective synchronous method in a task, but do allow scripts to run asynchronously. To cancel/abort a long running a script the host must use a globals object to signal a boolean or similar variable that the script can monitor. Demos added for both methods in V1.0.10.
If script gets stuck, say in an infinite loop, there's no way to halt it.