Advertisement
Lauda

Untitled

May 13th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.69 KB | None | 0 0
  1. private static void Main()
  2.         {
  3.             var counter = 0;
  4.             var thread = new Thread(() =>
  5.             {
  6.                 try
  7.                 {
  8.                     counter++;
  9.                     try
  10.                     {
  11.                         Thread.Sleep(100);
  12.                     }
  13.                     catch (ThreadAbortException)
  14.                     {
  15.                         counter++;
  16.                     }
  17.                     catch (SystemException)
  18.                     {
  19.                         counter++;
  20.                     }
  21.                     finally
  22.                     {
  23.                         ++counter;
  24.                     }
  25.                 }
  26.                 catch (ThreadAbortException)
  27.                 {
  28.                     counter++;
  29.                 }
  30.             })
  31.             { IsBackground = true };
  32.  
  33.             thread.Start();
  34.             Thread.Sleep(100);
  35.             thread.Abort();
  36.             thread.Join();
  37.  
  38.             var temp = counter;
  39.             var totalCount = temp++;
  40.             Console.WriteLine("Total count = {0}", totalCount); // 0, 1, 2, 3 ili 4?
  41.             Console.ReadLine();
  42.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement