使用 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.