【问题标题】:visual studio doesnt catch ThreadAbortExceptionVisual Studio 没有捕捉到 ThreadAbortException
【发布时间】:2013-07-01 15:58:08
【问题描述】:

我已经在 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)

【问题讨论】:

    标签: visual-studio visual-studio-debugging threadabortexception


    【解决方案1】:

    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() );
            }
        }
    }
    

    【讨论】:

    • 正如我在原始问题中所说 - 我已经在调试异常中选择了 ThreadAbortException,但它仍然不会中断。
    • Thrown 列有勾选吗?
    猜你喜欢
    • 2016-01-23
    • 1970-01-01
    • 1970-01-01
    • 2011-08-13
    • 1970-01-01
    • 1970-01-01
    • 2013-02-05
    • 2020-10-19
    相关资源
    最近更新 更多