C# Program to Pause a Thread


To pause a thread in C#, use the sleep() method.

You need to set the milliseconds for which you want the thread to pause, for example, for 5 seconds, use −

Thread.Sleep(5000);

Example

Let us see how to loop through and set the sleep method to pause the thread.

Live Demo

using System;
using System.Threading;
namespace Sample {
   class Demo {
      static void Main(string[] args) {
         for (int i = 0; i < 10; i++) {
            Console.WriteLine("Sleep for 1 second!");
            Thread.Sleep(1000);
         }
         Console.ReadLine();
      }
   }
}

Output

Sleep for 1 second!
Sleep for 1 second!
Sleep for 1 second!
Sleep for 1 second!
Sleep for 1 second!
Sleep for 1 second!
Sleep for 1 second!
Sleep for 1 second!
Sleep for 1 second!
Sleep for 1 second!

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 19-Jun-2020

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements