

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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!
- Related Questions & Answers
- C# Program to Kill a Thread
- How to pause an ABAP program?
- C# Program to create a Simple Thread
- C# Program to Create a Thread Pool
- C# Program to pass Parameter to a Thread
- C# Program to display priority of Thread
- CSS pause property
- C# Program to Check status of Current Thread
- C# Program to display name of Current Thread
- C# Program to implement Sleep Method Of Thread
- How to get the thread ID from a thread in C#?
- Windows thread API in the C program
- How to create a thread in C#?
- CSS pause-after property
- CSS pause-before property
Advertisements