Last Updated : 11 Jul, 2025
In C#, we can schedule a thread for execution using the Thread class. The Thread.Start() method is responsible for scheduling a thread, allowing it to run when system resources are available. This method can be overloaded to pass parameters to the thread. Also, the Thread.Sleep() method can be used to pause execution for a specified duration.
1. Using Thread.Start()The Start() method changes the state of the current instance to Running, allowing the thread to execute its assigned task.
Syntax:
public void Start();
Exceptions:
Example:
C#
// C# program to illustrate the
// use of Start() method
using System;
using System.Threading;
public class Geeks
{
public static void Main()
{
// Creating and initializing a thread
Thread thr = new Thread(new ThreadStart(Job));
// Start the execution of Thread
// Using Start() method
thr.Start();
}
public static void Job()
{
for (int i = 0; i < 4; i++) {
Console.WriteLine(i);
}
}
}
2. Using Thread.Start(Object)
This method starts the execution of a thread and allows passing an object containing data to be used by the method the thread executes.
Syntax:
public void Start(object parameter);
Exceptions:
Example:
C#
// C# program to illustrate the
// use of Start(Object) method
using System;
using System.Threading;
class Geeks
{
public static void Main()
{
// Creating object of Geeks class
Geeks obj = new Geeks();
// Creating and initializing threads
Thread thr1 = new Thread(obj.Job1);
Thread thr2 = new Thread(Job2);
// Start the execution of Thread
// Using Start(Object) method
thr1.Start(01);
thr2.Start("Hello");
}
public void Job1(object value)
{
Console.WriteLine("Data of Thread 1 is: {0}",
value);
}
public static void Job2(object value)
{
Console.WriteLine("Data of Thread 2 is: {0}",
value);
}
}
Data of Thread 1 is: 1 Data of Thread 2 is: Hello3. Using Thread.Sleep()
The Thread.Sleep() method pauses the execution of the current thread for a specified duration, allowing other threads to execute.
Syntax:
public static void Sleep(int millisecondsTimeout);
Example:
C#
// C# Program to illustrate the
// Thread.Sleep method
using System;
using System.Threading;
class Geeks
{
static void Main()
{
Console.WriteLine("Starting...");
Thread.Sleep(300);
Console.WriteLine("300 milliseconds have passed.");
}
}
Starting... 300 milliseconds have passed.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4