【发布时间】:2012-01-04 11:52:07
【问题描述】:
我从“Windows 上的并发编程”一书中得到以下代码:
void Main()
{
try
{
try
{
Console.WriteLine("Inside Main Method");
Thread.CurrentThread.Abort();
}
catch(ThreadAbortException)
{
Console.WriteLine("Inside First Catch");
// Trying to swallow but CLR throws it again....
}
}
catch(ThreadAbortException)
{
Console.WriteLine("Inside Second Catch");
//Thread.ResetAbort();
}
}
我很想知道为什么 CLR 会重新抛出 ThreadAbortException ?它一直这样做,直到我调用“Thread.ResetAbort()”。其次,是否有任何其他系统定义的异常得到 CLR 的特殊处理?
【问题讨论】:
-
另请注意,调用 Thread.ResetAbort() 的代码需要特殊权限才能执行此操作。因此,如果您正在托管 CLR 或创建 AppDomain,您可能会使用此功能使中止线程更具确定性。
标签: c# multithreading clr threadabortexception