[Mono-dev] a question on ThreadAbortException

Brian Crowell mono-devel at fluggo.com
Fri Feb 24 12:30:38 EST 2006


huangyi wrote:
> My project need to run and schedule many scripts written by user (and 
> user can write code like "while(true) ;"), because the number of scripts 
> is huge, so i use a single thread running all the scripts.so i need a 
> function just like Abort() to interrupt the current script (if time out) 
> and go on to run next script, but i don't know how to implement that in 
> c/c++.

I'll warn you about something: The ThreadAbortException wasn't designed to be 
caught and ignored. According to specs, it will be thrown again at the end of 
any catch block that catches it. To cancel the thread abort, you would have to 
call the Thread.ResetAbort() method inside whatever catch block you use.

But therein lies another problem. If the user's scripting language supports it, 
the user can set up his own ThreadAbortException handler and either call 
Thread.Abort() or refuse to leave the catch block.

The .NET Framework 2.0 includes explicit support for what's called a "rude 
thread abort" which kills a thread and only guarantees that certain special 
finally blocks will be run, and no others. Does Mono have something similar?

I've considered this problem for running user scripts and concluded that 
whatever scripting language the user uses must allow me to define what a user 
can do, including setting up exception handlers and defining what external code 
is available (to limit access to Thread.ResetAbort()). I know there are 
scripting engines out there like that, but none comes to mind.

Does anyone have any recommendations?

--Brian



More information about the Mono-devel-list mailing list