c# 怎么获取进程运行速度_获取C#中正在运行的进程的列表

c# 怎么获取进程运行速度_获取C#中正在运行的进程的列表

c# 怎么获取进程运行速度

The System.Diagnostics namespace contains functions that allow you to manage processes, threads, eventlogs and performance information.

System.Diagnostics命名空间包含允许您管理进程,线程,事件日志和性能信息的函数。

The System.Diagnostics.Process object gives you access to functionality enabling you to manage system processes. We will use this object to get a list of running processes.

System.Diagnostics.Process对象使您可以访问使您能够管理系统进程的功能。 我们将使用该对象来获取正在运行的进程的列表。

Add this line to your using list:

将此行添加到您的使用列表:

using System.Diagnostics;

使用System.Diagnostics;

Now you can get a list of the processes with the Process.GetProcesses() method, as seen in this example:

现在,您可以使用Process.GetProcesses()方法获取进程列表,如以下示例所示:

Process[] processlist = Process.GetProcesses();

Process [] processlist = Process.GetProcesses();

foreach(Process theprocess in processlist){ Console.WriteLine(“Process: {0} ID: {1}”, theprocess.ProcessName, theprocess.Id); }

foreach(在进程列表中处理该进程){Console.WriteLine(“进程:{0} ID:{1}”,theprocess.ProcessName,theprocess.Id); }

Some interesting properties of the Process object:

Process对象的一些有趣的属性:

p.StartTime (Shows the time the process started) p.TotalProcessorTime (Shows the amount of CPU time the process has taken) p.Threads ( gives access to the collection of threads in the process)

p.StartTime(显示进程开始的时间)p.TotalProcessorTime(显示进程已花费的CPU时间)p.Threads(可访问进程中的线程集合)

The .NET framework really makes things simple!

.NET框架确实使事情变得简单!

翻译自: https://www.howtogeek.com/howto/programming/get-a-list-of-running-processes-in-c/

c# 怎么获取进程运行速度