# How to terminate runnig script?

**URL:** <https://discourse.mcneel.com/t/how-to-terminate-runnig-script/18715>\
**Category:** Rhino Developer\
**Created:** [April 8, 2015, 7:58pm UTC](https://discourse.mcneel.com/t/how-to-terminate-runnig-script/18715 "2015-04-08T19:58:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jwielebnowski](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@jwielebnowski](https://discourse.mcneel.com/u/jwielebnowski)\
**Post date:** [April 8, 2015, 7:58pm UTC](https://discourse.mcneel.com/t/how-to-terminate-runnig-script/18715/1 "2015-04-08T19:58:04Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![dale](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/dale/32/685184_2.png) [@dale](https://discourse.mcneel.com/u/dale)\
**Post date:** [April 8, 2015, 9:00pm UTC](https://discourse.mcneel.com/t/how-to-terminate-runnig-script/18715/2 "2015-04-08T21:00:03Z")

</div>

> [@jwielebnowski](#):
>
> That function does not return until script is done.

Yes, this is true.

> [@jwielebnowski](#):
>
> In the meantime in my scenario it is possible to execute another script through the same function call.

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

> [@jwielebnowski](#):
>
> How I can detect and cancel script(s) that are running and start a new one?

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

[https://github.com/dalefugier/SampleCsEventWatcher](https://github.com/dalefugier/SampleCsEventWatcher)
