Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
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!
Advertisements