daily pastebin goal
90%
SHARE
TWEET

Untitled

a guest Mar 20th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void AbortThreadBySharedVariable()
  2.         {
  3.             var tickRunning = true;
  4.             Thread tickThread = new Thread(() =>
  5.             {
  6.                 while (tickRunning)
  7.                 {
  8.                     Console.WriteLine("Tick");
  9.                     Thread.Sleep(1000);
  10.                 }
  11.             });
  12.             tickThread.Start();
  13.             Console.WriteLine("Press a key to stop the clock");
  14.             //This would stop the loop thereby stops the thread from execution
  15.             tickRunning = false;
  16.             Console.WriteLine("Press a key to exit");
  17.             Console.ReadKey();
  18.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top