Process.Id 属性

获取关联进程的唯一标识符。

**命名空间:**System.Diagnostics
**程序集:**System(在 system.dll 中)

语法

声明
Public ReadOnly Property Id As Integer
用法
Dim instance As Process
Dim value As Integer

value = instance.Id
public int Id { get; }
public:
property int Id {
    int get ();
}
/** @property */
public int get_Id ()
public function get Id () : int

属性值

Process 实例引用的、由系统生成的进程的唯一标识符。

异常

异常类型 条件

InvalidOperationException

尚未设置进程的 Id 属性。

- 或 -

没有与此 Process 对象关联的进程。

PlatformNotSupportedException

该平台为 Windows 98 或 Windows Millennium Edition (Windows Me);如果将 ProcessStartInfo.UseShellExecute 属性设置为 false,则可以在 Windows 98 和 Windows Me 上访问此属性。

备注

如果关联的进程没有运行,则进程 Id 无效。因此,在尝试检索 Id 属性之前,应确保该进程正在运行。在进程终止前,进程标识符在整个系统中唯一地标识进程。

通过将进程标识符传递给 GetProcessById 方法,可以将正在本地或远程计算机上运行的进程连接到新的 Process 实例。GetProcessById 是创建新组件并自动为新的 Process 实例设置 Id 属性的 static 方法。

系统可重用进程标识符。Id 属性值仅当关联进程在运行中时才是唯一的。进程终止后,系统可对不相关的进程重用 Id 属性值。

由于标识符在系统中是唯一的,所以,作为传递 Process 实例的替代方式,还可以将标识符传递给其他线程。此操作既可节省系统资源,又可保证正确标识进程。

Windows 98, Windows Millennium Edition 平台说明: 如果在启动进程时 ProcessStartInfo.UseShellExecute 设置为 true,则此属性在此平台上不可用。

.NET Framework 安全性

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0

请参见

参考

Process 类
Process 成员
System.Diagnostics 命名空间
Process.Handle 属性
GetProcessById