在windows 10 UWP C# 中获取内存使用、CPU 使用、磁盘使用
Get the memory usage, CPU usage, disk usage in windows 10 UWP C#
我有 windows 10 个 UWP 应用,我想在 运行 时将信息(内存使用、CPU 使用、磁盘使用)写入此应用的文件中前景或背景。
那么,如何在 C# 中的 windows 10 UWP 中获取内存使用量、CPU 使用量、磁盘使用量?
我们可以使用 MemoryManager
class,它提供对应用程序内存使用情况信息的访问。我们可以使用 ProcessDiagnosticInfo.CpuUsage
和 ProcessDiagnosticInfo.DiskUsage
来获取 CPU 使用率,当前进程的磁盘使用率。
ProcessCpuUsage class has no constructor, it provides access to data about the CPU usage of a process. And this class only has a GetReport method, which gets the ProcessCpuUsageReport for the process. With ProcessCpuUsageReport
class, we can get KernelTime and UserTime 被进程消耗。
为了得到一个ProcessCpuUsage
对象,我们需要使用ProcessDiagnosticInfo.CpuUsage property. This is one of the properties in ProcessDiagnosticInfo class. This class provides diagnostic information about a process, such as CPU usage, disk usage, memory usage and so on. And ProcessDiagnosticInfo
class has two static methods: GetForCurrentProcess and GetForProcesses来帮助我们得到ProcessDiagnosticInfo
.
但请注意,这两种方法只能获取到与您自己的应用程序相关的ProcessDiagnosticInfo。 GetForProcesses 方法可以 return 所有 运行 进程的 ProcessDiagnosticInfo
个对象的列表。但这里的 "all running processes" 表示同一 App Container 中的所有 运行 进程。
我有 windows 10 个 UWP 应用,我想在 运行 时将信息(内存使用、CPU 使用、磁盘使用)写入此应用的文件中前景或背景。
那么,如何在 C# 中的 windows 10 UWP 中获取内存使用量、CPU 使用量、磁盘使用量?
我们可以使用 MemoryManager
class,它提供对应用程序内存使用情况信息的访问。我们可以使用 ProcessDiagnosticInfo.CpuUsage
和 ProcessDiagnosticInfo.DiskUsage
来获取 CPU 使用率,当前进程的磁盘使用率。
ProcessCpuUsage class has no constructor, it provides access to data about the CPU usage of a process. And this class only has a GetReport method, which gets the ProcessCpuUsageReport for the process. With ProcessCpuUsageReport
class, we can get KernelTime and UserTime 被进程消耗。
为了得到一个ProcessCpuUsage
对象,我们需要使用ProcessDiagnosticInfo.CpuUsage property. This is one of the properties in ProcessDiagnosticInfo class. This class provides diagnostic information about a process, such as CPU usage, disk usage, memory usage and so on. And ProcessDiagnosticInfo
class has two static methods: GetForCurrentProcess and GetForProcesses来帮助我们得到ProcessDiagnosticInfo
.
但请注意,这两种方法只能获取到与您自己的应用程序相关的ProcessDiagnosticInfo。 GetForProcesses 方法可以 return 所有 运行 进程的 ProcessDiagnosticInfo
个对象的列表。但这里的 "all running processes" 表示同一 App Container 中的所有 运行 进程。