C# 中的主執行緒與子執行緒
主執行緒
程序中首先執行的執行緒稱為主執行緒。當 C# 程式開始執行時,會自動建立主執行緒。
子執行緒
使用 Thread 類建立的執行緒稱為主執行緒的子執行緒。
以下是一個示例,展示如何建立主執行緒和子執行緒 −
示例
using System;
using System.Threading;
namespace Demo {
class Program {
static void Main(string[] args) {
Thread th = Thread.CurrentThread;
th.Name = "MainThread";
Console.WriteLine("This is {0}", th.Name);
Console.ReadKey();
}
}
}輸出
This is MainThread
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言
C++
C#
MongoDB
MySQL
Javascript
PHP