使用 C# 程式顯示執行緒的優先順序


要顯示 C# 中執行緒的優先順序,請使用 Priority 屬性。

首先,使用 currentThread 屬性顯示有關執行緒的資訊 −

Thread thread = Thread.CurrentThread;

現在使用 thread.Priority 屬性顯示執行緒的優先順序 −

thread.Priority

例項

讓我們看一看完整的程式碼,以在 C# 中顯示執行緒的優先順序。

線上演示

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

更新於: 2020-06-19

303 次瀏覽

開啟您的 職業生涯

完成課程獲得認證

開始吧
廣告
© . All rights reserved.