Tag: 最终

ThreadAbortException最终可以跳过吗?

我读过的所有内容声称线程中止将在从ThreadAbortException结束之前执行finally块。 我想确认这一点,以便我可以计划如何处理可以无限期挂起的第三方代码。 但是下面的测试让我困惑: public void runTest(DateTime deadline) { testThread = new Thread(() => { try { Console.WriteLine(“test thread started at ” + DateTime.Now.ToShortTimeString()); while (true) { } } finally { Console.WriteLine(“test thread entered FINALLY at ” + DateTime.Now.ToShortTimeString()); while (true) { } } }); testThread.Start(); while (testThread.IsAlive && deadline.Subtract(DateTime.Now).TotalSeconds > 0) { Console.WriteLine(“main thread while […]