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.