请在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 。所以呢?没有一只猴子知道答案吗?