我在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)
答案 0 :(得分:0)
Redirect()调用End(),它在完成时抛出ThreadAbortException异常。这是此类例外的一个来源。
打破异常选择 Debug->异常和公共语言运行时异常将检查Thrown列。
您可以通过在控制台应用程序中运行此示例代码来验证您的设置是否正确。调试器应该在线程中止的位置停止。
using System.Threading;
using System.Threading.Tasks;
namespace AbortThread
{
class Program
{
static void Main( string[] args )
{
Task.Run( () => Thread.CurrentThread.Abort() );
}
}
}