Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Các phương thức của lớp Thread trong C#

Một số phương thức phổ biến của lớp Thread: Start, Sleep, Join, Abort. Danh sách đầy đủ:

STTPhương thức & Mô tả
1public void Abort()
Ném ThreadAbortException để bắt đầu chấm dứt thread.
2public static LocalDataStoreSlot AllocateDataSlot()
Cấp phát slot dữ liệu vô danh cho tất cả thread.
3public static LocalDataStoreSlot AllocateNamedDataSlot(string name)
Cấp phát slot dữ liệu có tên cho tất cả thread.
4public static void BeginCriticalRegion()
Thông báo host chuẩn bị vào vùng codecritical.
5public static void BeginThreadAffinity()
Thông báo host code managed phụ thuộc OS thread identity.
6public static void EndCriticalRegion()
Thông báo host kết thúc vùng critical.
7public static void EndThreadAffinity()
Thông báo host kết thúc phụ thuộc thread identity.
8public static void FreeNamedDataSlot(string name)
Xóa liên kết tên-slot cho tất cả thread.
9public static Object GetData(LocalDataStoreSlot slot)
Lấy giá trị từ slot trên thread hiện tại.
10public static AppDomain GetDomain()
Trả về AppDomain hiện tại thread đang chạy.
11public static AppDomain GetDomainID()
Trả về định danh AppDomain duy nhất.
12public static LocalDataStoreSlot GetNamedDataSlot(string name)
Tra cứu slot dữ liệu có tên.
13public void Interrupt()
Ngắt thread ở trạng thái WaitSleepJoin.
14public void Join()
Chặn thread gọi cho đến khi thread kết thúc.
15public static void MemoryBarrier()
Đồng bộ truy cập bộ nhớ.
16public static void ResetAbort()
Hủy yêu cầu Abort cho thread hiện tại.
17public static void SetData(LocalDataStoreSlot slot, Object data)
Đặt dữ liệu vào slot trên thread đang chạy.
18public void Start()
Bắt đầu thread.
19public static void Sleep(int millisecondsTimeout)
Tạm dừng thread một khoảng thời gian.
20public static void SpinWait(int iterations)
Làm thread chờ số lần lặp xác định.