
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
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 Articles
- How to pause an ABAP program?
- C# Program to Kill a Thread
- C# Program to create a Simple Thread
- C# Program to Create a Thread Pool
- C# Program to pass Parameter to a Thread
- CSS pause property
- C# Program to display priority of Thread
- CSS pause-after property
- CSS pause-before property
- Getting Selenium to pause for X seconds.
- C# Program to Check status of Current Thread
- C# Program to display name of Current Thread
- C# Program to implement Sleep Method Of Thread
- What is the Linux Equivalent to DOS Pause?
- How to pause search history in YouTube App

Advertisements