I have several Jint engines running different scripts. Sometimes I need to pause their execution and resume it later. My solution at the moment is to run each engine in its own thread and then use ManualResetEvent
or similar to pause them as needed. This works fine.
Unfortunately in production, I cannot afford giving a thread to each Jint engine. The ideal scenario is if I could just run them all from the main thread, and pause each as needed e.g.
engines[6338].Pause();
...
engines[6338].Resume();
Without blocking the main thread either (due to UI).
I checked the Jint Debugger example as it probably has functionality to pause engines, but their solution/suggestion is actually the same I had originally: to use threads if you don't want to block the main thread:
private void Pause(DebugInformation e)
{
currentInfo = e;
string line = sources.GetLine(e.Location);
// Output the location we're at:
commandLine.OutputPosition(e.Location, line);
// In this - single threaded - example debugger, we let Console.ReadLine take care of blocking the execution.
// In debuggers involving a UI or in a debug server, we'd need script execution to be on a separate thread
// from the UI/server, and use e.g. a ManualResetEvent, or a message queue loop here to block until the user
// signals that the execution should continue.
commandLine.Input();
}
Is there a way to pause/resume a Jint engine's execution without using threading?