I would suppose a new thread would be called by timers, COM objects, /run commands. However, I'm not sure if this is correct.
But I would recommend implementing my suggestion into your script.
It will help you now, and It will help you again if there is another error.

Another option would be to make a temporary hash table, and use error catching to dump the hash table to a file, and halting the script. If no errors or anything happen, It would just free the hash table and make it once a alias/etc is called again.