ProcessThread 类

定义

表示操作系统进程线程。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. 若要直接释放类型,请在 Disposetry/ 块中调用其 catch 方法。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 对象的集合,请获取 Process 实例的 Threads 属性。To get a collection of all the ProcessThread objects associated with the current process, get the Threads property of the Process instance.

属性

BasePriority

获取线程的基本优先级。Gets the base priority of the thread.

CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(继承自 Component)
Container

获取 IContainer,它包含 ComponentGets 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

获取或设置一个值,该值指示每当关联线程的进程主窗口接收焦点时,操作系统是否暂时提升该线程的优先级。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

获取或设置 ISiteComponentGets 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)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。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 使用的非托管资源,并选择性地释放托管资源。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()

检索控制此实例的生存期策略的当前生存期服务对象。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()

返回包含 String 的名称的 Component(如果有)。Returns 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)

适用于

另请参阅