0

I am implementing Jurassic script engine, how do I limit how long a script will take?

    string ExcutingFunction = " for(var i=0;i<1000000;i++){ i%2; } ";
    ScriptEngine  ScrptingEngine = new ScriptEngine();
    ScrptingEngine.Execute(ExcutingFunction);
Bill Software Engineer
  • 7,362
  • 23
  • 91
  • 174

1 Answers1

2

Jurassic does not have an built-in way to limit the execution time of a script. Because Jurassic compiles JavaScript methods into IL code, there is no easy way to provide a timeout functionality without affecting performance.

However, it is possible to use Thread.Abort() to raise a ThreadAbortException in the thread that executes the script. One possibility is to run ScriptEngine.Execute() in a new thread and call thread.Abort() in the current thread if the new thread does not complete after a specific time.

Source

If you read through the documentation, they do have suggestions for how to do this but it is a bit lengthy and involved.

Community
  • 1
  • 1
Mike Cluck
  • 31,869
  • 13
  • 80
  • 91