Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement