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

更新於: 19-6-2020

303 次瀏覽

開啟您的事業

完成該課程以獲得認證

開始
廣告
© . All rights reserved.