C#主執行緒


在進程中建立的第一個執行緒稱為主執行緒。它第一個開始,最後一個結束。

下面來看看 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