Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void AbortThreadBySharedVariable()
- {
- var tickRunning = true;
- Thread tickThread = new Thread(() =>
- {
- while (tickRunning)
- {
- Console.WriteLine("Tick");
- Thread.Sleep(1000);
- }
- });
- tickThread.Start();
- Console.WriteLine("Press a key to stop the clock");
- //This would stop the loop thereby stops the thread from execution
- tickRunning = false;
- Console.WriteLine("Press a key to exit");
- Console.ReadKey();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement