[英]ProcessCpuUsage class - Resources Monitor
I want create Resources monitor as UWP application. 我想将资源监视器创建为UWP应用程序。 I read a lot about performanceCounter class from System.Diagnostics but... this class is not contain to UWP.
我从System.Diagnostics中阅读了很多关于performanceCounter类的信息,但是...该类不包含在UWP中。 Then i read about some native classes but my skill is too low to implement this yet ;/.
然后,我了解了一些本机类,但是我的技能太低,无法实现; //。
Then i found ProcessCpuUsage class Windows.SystemDiagnostics; 然后我找到了ProcessCpuUsage类Windows.SystemDiagnostics; and i tried implements this class but i cant find info about constructors and i dont know how implements it?
我试过实现此类,但是我找不到有关构造函数的信息,我也不知道如何实现它? What info can i get from this class ?
我可以从这堂课中学到什么信息?
In my app i need string with cpu/ram usage, and info about free disk space, and i want to show it as widget. 在我的应用程序中,我需要使用cpu / ram用法的字符串以及有关可用磁盘空间的信息,并且我想将其显示为小部件。 Please Help.
请帮忙。
ProcessCpuUsage class has no constructor, it provides access to data about the CPU usage of a process. ProcessCpuUsage类没有构造函数,它提供对有关进程CPU使用率的数据的访问。 And this class only has a GetReport method, which gets the ProcessCpuUsageReport for the process.
并且此类仅具有GetReport方法,该方法获取流程的ProcessCpuUsageReport 。 With
ProcessCpuUsageReport
class, we can get KernelTime and UserTime consumed by the process. 使用
ProcessCpuUsageReport
类,我们可以获取进程消耗的KernelTime和UserTime 。
To get a ProcessCpuUsage
object, we need use ProcessDiagnosticInfo.CpuUsage property. 要获取
ProcessCpuUsage
对象,我们需要使用ProcessDiagnosticInfo.CpuUsage属性。 This is one of the properties in ProcessDiagnosticInfo class. 这是ProcessDiagnosticInfo类的属性之一。 This class provides diagnostic information about a process, such as CPU usage, disk usage, memory usage and so on.
此类提供有关进程的诊断信息,例如CPU使用率,磁盘使用率,内存使用率等。 And
ProcessDiagnosticInfo
class has two static methods: GetForCurrentProcess and GetForProcesses that help us to get the ProcessDiagnosticInfo
. ProcessDiagnosticInfo
类具有两个静态方法: GetForCurrentProcess和GetForProcesses ,它们可以帮助我们获取ProcessDiagnosticInfo
。
However, please note that these two methods can only get the ProcessDiagnosticInfo
related to your own app . 但是,请注意,这两种方法只能获取与您自己的应用程序相关的
ProcessDiagnosticInfo
。 GetForProcesses
method can return a list of ProcessDiagnosticInfo
objects for all running processes. GetForProcesses
方法可以返回所有正在运行的进程的ProcessDiagnosticInfo
对象的列表。 But here the "all running processes" means all running processes in the same App Container. 但是这里的“所有正在运行的进程”是指同一App容器中的所有正在运行的进程。 For example, for a UWP with out-of-process background tasks ,
GetForProcesses
method may return several ProcessDiagnosticInfo
s including running background tasks. 例如,对于具有进程外后台任务的UWP,
GetForProcesses
方法可能返回几个ProcessDiagnosticInfo
包括正在运行的后台任务。 But for a simple UWP app, it may always return one ProcessDiagnosticInfo
. 但是对于一个简单的UWP应用,它可能总是返回一个
ProcessDiagnosticInfo
。 This method can't return diagnostic informations for all running processes in the computer/device as UWP apps are running in app containers and isolated from each other. 由于UWP应用程序正在应用程序容器中运行并且彼此隔离,因此该方法无法返回计算机/设备中所有正在运行的进程的诊断信息。
So if you are going to create a resources monitor application, UWP may be not a good choice. 因此,如果要创建资源监视器应用程序,则UWP可能不是一个好选择。 Classic desktop apps might be better for your scenario.
经典桌面应用程序可能更适合您的方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.