One of the attributes that controls the behavior of a thread is its priority. The . Net Runtime environment executes threads based on their priority. Only one thread is executed by the CPU at a time. Therefore, the threads, which are the runnable state for execution, queue up for their turn to get executed by the processor. The threads are fixed-priority scheduled. Each thread with its priority has its position in the thread queue of the processor.
Defining Thread Priority:
Thread priority is the property that specifies the priority of one thread with respect to the priority of another thread. Execution of multiple threads is scheduled on a single processor in a specified order.
Thread priority can be defined as:
• Above normal
• Below normal
A thread with higher priority runs before threads, which have lower priority. If C# encounters another thread with higher priority, the current thread is pushed back; and the thread with the higher priority is executed.
The . Net runtime system selects the runnable thread with the highest priority of execution when a number of threads get ready to execute. The next thread of lower priority starts executing if the higher priority thread stops or becomes not runnable. A thread is pushed back in the queue by another thread if it is waiting for an I/O operation. A thread can also be pushed back in the queue when the time for which the Sleep ( ) method was called on another higher priority thread is over.