在進程中創建的第一個線程稱為主線程。它第一個開始,最後一個結束。
下麵來看看 C# 中主線程的一個例子。參考以下示例代碼 -
using System;
using System.Threading;
public class ThreadExample
{
public static void Main(string[] args)
{
Thread t = Thread.CurrentThread;
t.Name = "MainThread";
Console.WriteLine(t.Name);
}
}
執行上面示例代碼,得到以下結果 -
MainThread
上一篇:
C# Thread類
下一篇:
C#線程實例