本文整理汇总了C#中System.Diagnostics.Process.GetProcessById方法的典型用法代码示例。如果您正苦于以下问题:C# Process.GetProcessById方法的具体用法?C# Process.GetProcessById怎么用?C# Process.GetProcessById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.Process
的用法示例。
在下文中一共展示了Process.GetProcessById方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindToRunningProcesses
//引入命名空间
using System;
using System.Diagnostics;
using System.ComponentModel;
namespace MyProcessSample
{
class MyProcess
{
void BindToRunningProcesses()
{
// Get the current process.
Process currentProcess = Process.GetCurrentProcess();
// Get all processes running on the local computer.
Process[] localAll = Process.GetProcesses();
// Get all instances of Notepad running on the local computer.
// This will return an empty array if notepad isn't running.
Process[] localByName = Process.GetProcessesByName("notepad");
// Get a process on the local computer, using the process id.
// This will throw an exception if there is no such process.
Process localById = Process.GetProcessById(1234);
// Get processes running on a remote computer. Note that this
// and all the following calls will timeout and throw an exception
// if "myComputer" and 169.0.0.0 do not exist on your local network.
// Get all processes on a remote computer.
Process[] remoteAll = Process.GetProcesses("myComputer");
// Get all instances of Notepad running on the specific computer, using machine name.
Process[] remoteByName = Process.GetProcessesByName("notepad", "myComputer");
// Get all instances of Notepad running on the specific computer, using IP address.
Process[] ipByName = Process.GetProcessesByName("notepad", "169.0.0.0");
// Get a process on a remote computer, using the process id and machine name.
Process remoteById = Process.GetProcessById(2345, "myComputer");
}
static void Main()
{
MyProcess myProcess = new MyProcess();
myProcess.BindToRunningProcesses();
}
}
}
示例2: EnumThreadsForPid
//引入命名空间
using System;
using System.Diagnostics;
class MainClass
{
public static void EnumThreadsForPid(int pID)
{
Process theProc;
try {
theProc = Process.GetProcessById(pID);
} catch {
Console.WriteLine("-> Sorry...bad PID!");
return;
}
Console.WriteLine("Here are the thread IDs for: {0}", theProc.ProcessName);
ProcessThreadCollection theThreads = theProc.Threads;
foreach(ProcessThread pt in theThreads)
{
string info = string.Format("-> Thread ID: {0}\tStart Time {1}\tPriority {2}", pt.Id , pt.StartTime.ToShortTimeString(), pt.PriorityLevel);
Console.WriteLine(info);
}
}
static void Main(string[] args)
{
int theProcID = 10001;
EnumThreadsForPid(theProcID);
}
}