Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace Ending
- {
- class Program
- {
- static void Main(string[] args)
- {
- Thread watek = new Thread(() =>
- {
- Console.WriteLine("Wątek uruchomiony i idzie spać...");
- try
- {
- Thread.Sleep(2000);
- }
- catch (ThreadInterruptedException tiex)
- {
- Console.WriteLine("Złapałem wyjątek ThreadInterruptedException: " + tiex.Message);
- }
- catch (ThreadAbortException taex)
- {
- Thread.ResetAbort();
- Console.WriteLine("Złapałem wyjątek ThreadAbortException: " + taex.Message);
- }
- finally
- {
- Console.WriteLine("Wykonuję finally");
- }
- Console.WriteLine("Wątek kończy działanie normalnie");
- });
- watek.Start();
- /*
- * interrupt
- watek.Interrupt();
- watek.Join();
- * */
- /*
- * abort
- watek.Abort();
- watek.Join();
- * */
- Thread.Sleep(1000);
- watek.Abort();
- watek.Join();
- Console.WriteLine("To już jest koniec, naciśnij ENTER...");
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement