Open In App

C# Thread Priority in Multithreading

Last Updated : 11 Jul, 2025
Comments
Improve
Suggest changes
5 Likes
Like
Report

In a multithreaded environment, each thread has a priority that determines how frequently the thread is allocated CPU resources by the operating system. The Thread.Priority property in C# is used to set or get the priority of a thread.

  • A programmer can explicitly assign a priority to a thread using the Priority property.
  • By default, a thread's priority is set to Normal.
  • The operating system handles thread scheduling, but priorities influence how threads are executed.
  • Setting priorities incorrectly can lead to thread starvation, where lower-priority threads may not get enough CPU time.
  • A high-priority thread does not guarantee that it will execute before a low-priority thread because of context switching and other OS-level scheduling mechanisms.
  • The thread priority always depends on the process priority (the parent container).

Thread Priority Levels

The ThreadPriority enum under the System.Threading namespace specifies the following priority levels:

Priority Level

Description

Value

Highest

Highest priority for a thread.

4

AboveNormal

Higher than Normal priority.

3

Normal (Default)

Default priority.

2

BelowNormal

Lower than Normal priority.

1

Lowest

Lowest priority for a thread.

0

Syntax:

public ThreadPriority Priority{ get; set; }

Exceptions:

  • ThreadStateException: If the thread has reached a final state, such as Aborted.
  • ArgumentException: If the value specified for a set operation is not a valid ThreadPriority value.

Example 1: This example demonstrates how to set and get the priority of threads.


Output
The priority of T1 is: Normal
The priority of T2 is: Highest
The priority of T3 is: BelowNormal

Example 2: This example demonstrates how thread priority can influence thread execution.


Output
T1 thread is working..
T2 thread is working..

Similar Reads