VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/how-to-schedule-a-thread-for-execution-in-c-sharp/

⇱ How to Schedule a Thread for Execution in C#? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Schedule a Thread for Execution in C#?

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:

  • ThreadStateException: If the thread has already been started.
  • OutOfMemoryException: If there is not enough memory available to start a thread.

Example:


Output
0
1
2
3

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:

  • ThreadStateException: If the thread has already been started.
  • OutOfMemoryException: If there is not enough memory available to start a thread.
  • InvalidOperationException: If the thread was created using a ThreadStart delegate instead of a ParameterizedThreadStart delegate.

Example:


Output
Data of Thread 1 is: 1
Data of Thread 2 is: Hello

3. 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:


Output
Starting...
300 milliseconds have passed.
Comment

Explore