簡體   English   中英

Visual Studio沒有捕獲ThreadAbortException

[英]visual studio doesnt catch ThreadAbortException

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

Redirect ()調用End(),它在完成時引發ThreadAbortException異常。 這是此類異常的來源之一。

要中斷異常,請選擇“調試”->“異常”,對於“公共語言運行時異常”,請在“拋出”列中進行檢查。

您可以通過在控制台應用程序中運行此示例代碼來驗證設置是否正確。 調試器應在線程中止的位置停止。

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

namespace AbortThread
{
    class Program
    {
        static void Main( string[] args )
        {
            Task.Run( () => Thread.CurrentThread.Abort() );
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM