C#程序以显示当前线程的名称


若要以 C#显示当前线程的名称,请使用 Name 属性。

首先,使用 currentThread 属性显示有关线程的信息 −

Thread thread = Thread.CurrentThread;

现在使用 thread.Name 属性显示线程的名称 −

thread.Name

举例

让我们看看完整的代码在 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 Name = {0}", thread.Name);
         Console.ReadKey();
      }
   }
}

输出

Thread Name = My Thread

更新于:19-Jun-2020

183 人浏览

开启你的 职业生涯

完成课程即可获得认证

开始
广告
© . All rights reserved.