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

本文介绍如何使用C#的System.Diagnostics命名空间中的Process对象来获取当前系统中正在运行的所有进程的信息,包括进程名和ID,并展示了如何访问进程的开始时间、CPU占用时间和线程集合等属性。
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# 怎么获取进程运行速度

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值