Mega Code Archive

 
Categories / C# Book / 10 Thread
 

0633 Sleep a thread

You can include a timeout when calling Join, either in milliseconds or as a TimeSpan. It then returns true if the thread ended or false if it timed out. Thread.Sleep pauses the current thread for a specified period: using System; using System.Threading; class ThreadTest { static void Main() { Thread.Sleep(TimeSpan.FromHours(1)); // sleep for 1 hour Thread.Sleep(500); // sleep for 500 milliseconds } }