首頁  >  文章  >  後端開發  >  C#顯示執行緒優先權的程序

C#顯示執行緒優先權的程序

王林
王林轉載
2023-08-31 17:17:021098瀏覽

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

以上是C#顯示執行緒優先權的程序的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除