How to terminate runnig script?

I am executing a command using:

RhinoApp.RunScript(scriptCommand, echoScript);

That function does not return until script is done. In the meantime in my scenario it is possible to execute another script through the same function call. How I can detect and cancel script(s) that are running and start a new one?

I tried issue ESC key and cancel command but that did not work (I suspect the reason is that the script is running in a separate thread)

Yes, this is true.

No. Rhino is not a multi-threaded application. Thus, it can only run one command or command script at a time.

Often, developers will watch for a Command.EndCommand event. Here is a comprehensive event handling example you can review.