开发者

How do I terminate a .NET thread that has had its call stack corrupted?

I have a thread in my application that is running code that can potentially cause call stack corruption ( my application is a testing tool for dlls ).

Assuming that I have a method of detecting if the child thread is misbehaving, how would I terminate it? From what I read, calling Thread.Abor开发者_StackOverflow社区t() on the misbehaving thread would be equivalent to raising an exception inside it.I fear that that not be a good idea, provided the call stack of the thread might be corrupted.Any suggestions?


If you are running untrusted code that could corrupt your process run that code in a separate process and communicate with it using interprocess communication. If you want to terminate the untrusted code early, you can just kill the process.


If code is misbehaving, it can do anything, and it can affect anything in the entire process, on any thread.

The most reliable solution is to run the untrusted code in a separate process, then terminate the process if it misbehaves.


Load the DLL into a new AppDomain and run the code in the DLL from there using the AppDomain.DoCallBack method.


In addition to the accept answer, I'd like to add that it is trivially easy to ignore Thread.Abort.

try
{
    ...
}
catch (ThreadAbortException)
{
   Thread.ResetAbort();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜