0

我已经在 VS 调试异常对话框中设置了 ThreadAbortException,但它永远不会中断,即使我在我的代码中明确地使用了 Thread.Abort()。

我可以在控制台中看到条目,例如:

A first chance exception of type 'System.Threading.ThreadAbortException' occurred in System.dll
An exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll but was not handled in user code

有什么方法可以让 VS 打破这些异常?(我在桌面使用 VS Express 2012,但如果需要可以访问完整的 VS)

4

1 回答 1

0

Redirect () 调用 End(),它在完成时抛出 ThreadAbortException 异常。这是此类异常的来源之一。

要中断异常,请选择 Debug->Exceptions 并为 Common Language Runtime Exceptions 勾选 Throw 列。

您可以通过在控制台应用程序中运行此示例代码来验证您的设置是否正确。调试器应该在线程被中止的地方停止。

using System.Threading;
using System.Threading.Tasks;

namespace AbortThread
{
    class Program
    {
        static void Main( string[] args )
        {
            Task.Run( () => Thread.CurrentThread.Abort() );
        }
    }
}
于 2014-01-30T18:27:13.230 回答