Recall that Richter wrote that UnhandledException interrupts the thread in which it occurred. I tried to apply it for the experiment. I wrote this code here:
class Program { static void ThrowException(object obj) { try { throw new Exception(); Console.Write("1");//Я знаю, что компилятор опустит эту строчку :D } catch { Console.WriteLine("--------------Exception was throwen."); throw; } } static void Main(string[] args) { Console.WriteLine("Are you ready for Tasks?"); Task.Run(() => ThrowException(null)); Thread.Sleep(1000); Console.WriteLine("Tasks OK"); Thread.Sleep(3000); Console.WriteLine("Are you ready for Threads?"); Thread thread = new Thread(() => ThrowException(null)); thread.Start(); Thread.Sleep(1000); Console.WriteLine("Threads OK"); Thread.Sleep(3000); Console.WriteLine("Are you ready for ThreadPool?"); ThreadPool.QueueUserWorkItem(ThrowException); Thread.Sleep(1000); Console.WriteLine("ThreadPool OK"); Console.ReadKey(true); } } With Task everything works as intended, but after this "magic" with Thread application stops. I googled and still do not understand, because in Microsoft Docs written
It is not clear that there has been a situation in the process of extracting.
Why is the application closing?
Thread.Sleep(1000);What can fly there? I ran the linkup, the framework I have is 4.5.1 - tym32167