作者:程序员老板梦 | 来源:互联网 | 2022-12-10 13:04
我正在尝试监视CPU和内存,并获得与TaskManager值匹配的值(或尽可能接近).到目前为止,我有:
static readonly PerformanceCounter IdleCounter = new PerformanceCounter("Processor", "% Idle Time", "_Total");
static readonly PerformanceCounter RamCounter = new PerformanceCounter("Memory", "Available MBytes");
public string f() {
return "cpu: " + (100-IdleCounter.NextValue()) + " , ram: " + RamCounter.NextValue() + "MB";
}
这给了cpu非常准确(与incManager比较)的值,尽管如果可能我想更接近.
对于内存,但它似乎不匹配,我得到一个数字,但我真正想要的是百分比像任务管理器显示..
有帮助吗?