Created
March 8, 2020 20:35
-
-
Save fatihbahceci/5fb9d1730a2cc87026f367c0718c002a to your computer and use it in GitHub Desktop.
C# Thread.IsAlive test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//C# Interactive code. (Ctrl + E, Ctrl + E) | |
using System.Threading; | |
volatile bool stop = false; | |
Thread thread = new Thread(() => { | |
while (stop == false) | |
{ | |
Thread.Sleep(500); | |
Console.WriteLine(DateTime.Now); | |
} | |
Console.WriteLine("Finished"); | |
}); | |
Task.Delay(5 * 1000).ContinueWith(x => { stop = true; }); | |
thread.Start(); | |
Thread.Sleep(100); | |
while (thread.IsAlive) { | |
Thread.Sleep(100); | |
Console.WriteLine("Still working"); | |
} | |
Console.WriteLine("Heyooo!"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment