Threading is normally used to suspends the current thread for the specified amount of time to execute your own block of code. In this article, I will show you how you can use Threading with Sleep method. Lets take one example to run for loop here and display message in each 5 seconds for 3 times
static void Main(string args)
Console.WriteLine("Thread Start Now");
for (int i = 0; i < 3; i++)
Console.WriteLine("Hello World " + i + " times execute after 5 seconds");
In above example, we used one for loop to execute output 3 times and 5 second waits for each. As we can see that in above output screensot.
Thread has two overloads with Sleep method
Suspends the current thread for the specified number of milliseconds. In this method, thread is suspended for specified milliseconds. Best practice is you should define your milliseconds in parameter.
Suspends the current thread for the specified amount of time. In this method, you need to define the time when thread should be suspended.
TimeSpan TimeInterval = new TimeSpan(0, 10, 0);
About the Author