ProcessThread 類別

定義

表示作業系統處理序 (Process) 執行緒。Represents an operating system process thread.

public ref class ProcessThread : System::ComponentModel::Component
public class ProcessThread : System.ComponentModel.Component
type ProcessThread = class
    inherit Component
Public Class ProcessThread
Inherits Component
繼承

備註

使用ProcessThread來取得目前正在系統上執行之執行緒的相關資訊。Use ProcessThread to obtain information about a thread that is currently running on the system. 例如, 這麼做可讓您監視執行緒的效能特性。Doing so allows you, for example, to monitor the thread's performance characteristics.

重要

此型別代表 IDisposable 介面。This type implements the IDisposable interface. 當您完成使用型別時,您應該直接或間接處置它。When you have finished using the type, you should dispose of it either directly or indirectly. 若要直接處置型別,請呼叫其 try/catch 區塊中的 Dispose 方法。To dispose of the type directly, call its Dispose method in a try/catch block. 若要間接處置它,請使用語言建構函式,例如 using (在 C# 中) 或 Using (在 Visual Basic 中)。To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). 如需詳細資訊,請參閱 IDisposable 介面文章中的<使用實作 IDisposable 的物件>一節。For more information, see the "Using an Object that Implements IDisposable" section in the IDisposable interface topic.

執行緒是透過程式執行的路徑。A thread is a path of execution through a program. 這是 Win32 排定的最小執行單位。It is the smallest unit of execution that Win32 schedules. 其中包含堆疊、CPU 暫存器的狀態, 以及系統排程器執行清單中的專案。It consists of a stack, the state of the CPU registers, and an entry in the execution list of the system scheduler.

處理常式是由一個或多個執行緒, 以及記憶體中程式的程式碼、資料和其他資源所組成。A process consists of one or more threads and the code, data, and other resources of a program in memory. 一般的程式資源包括開啟的檔案、信號和動態配置的記憶體。Typical program resources are open files, semaphores, and dynamically allocated memory. 處理常式的每個資源都是由該進程的所有線程所共用。Each resource of a process is shared by all that process's threads.

當系統排程器將執行控制提供給其中一個程式的執行緒時, 就會執行程式。A program executes when the system scheduler gives execution control to one of the program's threads. 排程器會決定應該執行的執行緒和時機。The scheduler determines which threads should run and when. 較低優先順序的執行緒可能會強制等候, 而較高優先順序的執行緒會完成其工作。A lower-priority thread might be forced to wait while higher-priority threads complete their tasks. 在多處理器電腦上, 排程器可以將個別執行緒移至不同的處理器, 進而平衡 CPU 負載。On multiprocessor computers, the scheduler can move individual threads to different processors, thus balancing the CPU load.

每個進程都是以單一執行緒開始, 也就是所謂的主要執行緒。Each process starts with a single thread, which is known as the primary thread. 任何執行緒都可以建立額外的執行緒。Any thread can create additional threads. 進程內的所有線程都會共用該進程的位址空間。All the threads within a process share the address space of that process.

主要執行緒不一定要位於集合中的第一個索引。The primary thread is not necessarily located at the first index in the collection.

注意

從 .NET Framework 版本2.0 開始, 在其他電腦上參考效能計數器資料的能力, 已針對許多 .NET Framework 方法和屬性而消除。Starting with the .NET Framework version 2.0, the ability to reference performance counter data on other computers has been eliminated for many of the .NET Framework methods and properties. 這是為了改善效能, 以及讓非系統管理員使用ProcessThread類別而進行的變更。This change was made to improve performance and to enable non-administrators to use the ProcessThread class. 因此, 某些未在舊版 .NET Framework 中取得例外狀況的應用程式, 現在可能會取得NotSupportedExceptionAs a result, some applications that did not get exceptions in earlier versions of the .NET Framework may now get a NotSupportedException. 受影響的方法和屬性太多, 無法在此列出, 但是例外狀況資訊已新增至受影響的成員主題。The methods and properties affected are too numerous to list here, but the exception information has been added to the affected member topics.

進程的執行緒會個別執行, 並不會察覺彼此, 除非您讓它們彼此可見。The threads of a process execute individually and are unaware of each other unless you make them visible to each other. 不過, 共用通用資源的執行緒必須使用信號或處理序間通訊的另一種方法來協調其工作。Threads that share common resources, however, must coordinate their work by using semaphores or another method of interprocess communication.

若要取得與目前進程相關ProcessThread聯之所有物件的集合, 請取得Threads Process實例的屬性。To get a collection of all the ProcessThread objects associated with the current process, get the Threads property of the Process instance.

屬性

BasePriority

取得執行緒的基礎優先權 (Base Priority)。Gets the base priority of the thread.

CanRaiseEvents

取得值,指出元件是否能引發事件。Gets a value indicating whether the component can raise an event.

(繼承來源 Component)
Container

取得包含 IContainerComponentGets the IContainer that contains the Component.

(繼承來源 Component)
CurrentPriority

取得執行緒的目前優先權。Gets the current priority of the thread.

DesignMode

取得值,指出 Component 目前是否處於設計模式。Gets a value that indicates whether the Component is currently in design mode.

(繼承來源 Component)
Events

取得附加在這個 Component 上的事件處理常式清單。Gets the list of event handlers that are attached to this Component.

(繼承來源 Component)
Id

取得執行緒的唯一識別項。Gets the unique identifier of the thread.

IdealProcessor

設定執行這個執行緒的慣用處理器。Sets the preferred processor for this thread to run on.

PriorityBoostEnabled

取得或設定數值,表示每當執行緒的處理序之主視窗接收到焦點 (Focus) 時,作業系統是否應該暫時提高相關執行緒的優先權。Gets or sets a value indicating whether the operating system should temporarily boost the priority of the associated thread whenever the main window of the thread's process receives the focus.

PriorityLevel

取得或設定執行緒的優先權層級。Gets or sets the priority level of the thread.

PrivilegedProcessorTime

取得執行緒在作業系統核心中執行程式碼所耗用的時間量。Gets the amount of time that the thread has spent running code inside the operating system core.

ProcessorAffinity

設定可以執行相關執行緒的處理器。Sets the processors on which the associated thread can run.

Site

取得或設定 ComponentISiteGets or sets the ISite of the Component.

(繼承來源 Component)
StartAddress

取得作業系統啟動這個執行緒所呼叫之函式的記憶體位址。Gets the memory address of the function that the operating system called that started this thread.

StartTime

取得作業系統啟動執行緒的時間。Gets the time that the operating system started the thread.

ThreadState

取得這個執行緒目前的狀態。Gets the current state of this thread.

TotalProcessorTime

取得這個執行緒使用處理器所耗用的總時間量。Gets the total amount of time that this thread has spent using the processor.

UserProcessorTime

取得相關執行緒在應用程式內部執行程式碼所耗用的時間量。Gets the amount of time that the associated thread has spent running code inside the application.

WaitReason

取得執行緒正在等候的原因。Gets the reason that the thread is waiting.

方法

CreateObjRef(Type)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(繼承來源 MarshalByRefObject)
Dispose()

釋放 Component 所使用的所有資源。Releases all resources used by the Component.

(繼承來源 Component)
Dispose(Boolean)

釋放 Component 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(繼承來源 Component)
Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

作為預設雜湊函數。Serves as the default hash function.

(繼承來源 Object)
GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
GetService(Type)

傳回表示 Component 或其 Container 所提供之服務的物件。Returns an object that represents a service provided by the Component or by its Container.

(繼承來源 Component)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(繼承來源 MarshalByRefObject)
ResetIdealProcessor()

重設這個執行緒的理想處理器,以指示沒有一個的理想處理器。Resets the ideal processor for this thread to indicate that there is no single ideal processor. 換句話說,沒有任何處理器是理想的。In other words, so that any processor is ideal.

ToString()

傳回任何包含 Component 名稱的 StringReturns a String containing the name of the Component, if any. 不應覆寫此方法。This method should not be overridden.

(繼承來源 Component)

事件

Disposed

當此元件由 Dispose() 方法的呼叫處置時發生。Occurs when the component is disposed by a call to the Dispose() method.

(繼承來源 Component)

適用於

另請參閱