C# - How to Print the Priority of Current Thread?

Here, we are going to learn how to print the priority of current thread in C#? By Nidhi Last updated : March 29, 2023

Types of Thread Priorities

There are the following types of priorities of a thread in C#,

  1. Zero
  2. Normal
  3. Below Normal
  4. Above Normal
  5. Highest

Here we print the priority of current thread on the console screen.

C# program to print the priority of current thread

/*
 *  Program to print the priority of current thread in C#.
 */

using System;
using System.Threading;

class ThreadEx {
  static void Main() {
    Thread Thr = Thread.CurrentThread;
    Thr.Name = "MyThread";

    Console.WriteLine("Information about current thread:");
    Console.WriteLine("\tName of the thread: " + Thr.Name);
    Console.WriteLine("\tPriority of thread: " + Thr.Priority);
  }
}

Output

Information about current thread:
        Name of the thread: MyThread
        Priority of thread: Normal
Press any key to continue . . .

Explanation

In the above program, we created a class ThreadEx that contains the Main() method. Here we created the thread Thr using Thread.CurrentThread property. Then we assigned the name of the thread and then print name and priority of thread on the console screen.

C# Thread Programs »

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.