|
Este artigo foi traduzido por máquina. Coloque o ponteiro do mouse sobre as frases do artigo para ver o texto original. Mais informações.
|
Tradução
Original
|
Propriedade Process.Id
Namespace: System.Diagnostics
Assembly: System (em System.dll)
| Exceção | Condição |
|---|---|
| InvalidOperationException | |
| PlatformNotSupportedException |
Observação sobre a plataforma :
using System; using System.Threading; using System.Security.Permissions; using System.Security.Principal; using System.Diagnostics; class ProcessDemo { public static void Main() { Process notePad = Process.Start("notepad"); Console.WriteLine("Started notepad process Id = " + notePad.Id); Console.WriteLine("All instances of notepad:"); // Get Process objects for all running instances on notepad. Process[] localByName = Process.GetProcessesByName("notepad"); int i = localByName.Length; while (i > 0) { // You can use the process Id to pass to other applications or to // reference that particular instance of the application. Console.WriteLine(localByName[i - 1].Id.ToString()); i -= 1; } Process chosen; i = localByName.Length; while (i > 0) { Console.WriteLine("Enter a process Id to kill the process"); string id = Console.ReadLine(); if (id == "") break; try { chosen = Process.GetProcessById(Int32.Parse(id)); } catch (Exception e) { Console.WriteLine("Incorrect entry."); continue; } if (chosen.ProcessName == "notepad") { chosen.Kill(); chosen.WaitForExit(); } i -= 1; } } }
- LinkDemand
para confiança total para o chamador imediato. Este membro não pode ser usado pelo código parcialmente confiável.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Função Server Core sem suporte), Windows Server 2008 R2 (Função Server Core com suporte com o SP1 ou posterior, Itanium sem suporte)
O .NET Framework não oferece suporte a todas as versões de cada plataforma. Para obter uma lista das versões com suporte, consulte .Requisitos de sistema do NET Framework.