Abort execution #252
Unanswered
daniel-schroeder-zeiss
asked this question in
Q&A
Replies: 1 comment
-
One possibility is the public static class ScriptEngineExtensions {
public static bool ExecuteWithExit(this ScriptEngine engine, string code) {
engine.Script.exit = new Action(() => ScriptEngine.Current.Interrupt());
try {
engine.Execute(code);
return true;
}
catch (ScriptInterruptedException) {
return false;
}
finally {
((ScriptObject)engine.Script).DeleteProperty("exit");
}
}
} And then: engine.AddHostType(typeof(Console));
engine.ExecuteWithExit(@"
Console.WriteLine('foo');
exit();
Console.WriteLine('bar'); // NOT REACHED
"); However, we can't guarantee that execution will always stop on the exact line of the Good luck! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
is there a good way to abort script execution from within the executed script? I'm looking for a way to implement something similar to nodes process.exit(), but I do not want to kill my whole process but only the currently executing script.
Beta Was this translation helpful? Give feedback.
All reactions