ใช้ property Priority ของคลาส Thread เพื่อดู/ตั้งค่าระดับความสำคัญของเธรด
ค่า Priority ที่เป็นไปได้ (enum ThreadPriority):
LowestBelowNormalNormal(ค่าเริ่มต้น)AboveNormalHighest
ตัวอย่างโค้ดเต็ม
using System;
using System.Threading;
namespace Demo {
class MyClass {
static void Main(string[] args) {
Thread thread = Thread.CurrentThread;
thread.Name = "My Thread";
Console.WriteLine("Thread Priority = {0}", thread.Priority);
Console.ReadKey();
}
}
}
ผลลัพธ์
Thread Priority = Normal
คำอธิบาย: Thread.CurrentThread ให้ออบเจ็กต์เธรดที่กำลังทำงานอยู่ สามารถตั้งค่า Priority ได้ด้วย thread.Priority = ThreadPriority.Highest;