使用ThreadAbortException和死锁在调试和发布中的不同行为

时间:2019-06-28 19:06:48

标签: c# debugging deadlock release threadabortexception

请在Debug和Release配置中使用Visual Studio 2017(可能还有其他版本)编译此代码:

static void Main(string[] args)
{
    var thread = new System.Threading.Thread(() =>
    {
        while (true)
        {
            try
            {
                Thread.Sleep(int.MaxValue);
            }
            catch { }
        }
    });

    thread.Start();
    thread.Join(1000);
    thread.Abort();
    thread.Join();
}

然后有人向我解释,为什么在Debug模式下完成并导致Release中的死锁

更新。追加其他“捕获”块将解决此问题(仍然不知道为什么):

catch (ThreadAbortException) { break; }

Update2 。所以呢?没有一只猴子知道答案吗?

0 个答案:

没有答案
相关问题