我在windows窗体上有一个按钮,按钮点击事件代码如下: PerformanceCounter pc = new PerformanceCounter();
pc.CategoryName = "Process";
pc.CounterName = "% Processor Time";
pc.InstanceName = "_Total";
pc.MachineName = ".";
string cpuCondition = "CPU使用率为:" + pc.NextValue().ToString() + "%";
MessageBox.Show(cpuCondition);可是为什么每次点击按钮显示的都是“CPU使用率为0%”,然后我打开任务管理器上看到CPU使用率并不是0%,然后就不知道问题出在哪了,请高手指点。。不甚感谢
pc.CategoryName = "Process";
pc.CounterName = "% Processor Time";
pc.InstanceName = "_Total";
pc.MachineName = ".";
string cpuCondition = "CPU使用率为:" + pc.NextValue().ToString() + "%";
MessageBox.Show(cpuCondition);可是为什么每次点击按钮显示的都是“CPU使用率为0%”,然后我打开任务管理器上看到CPU使用率并不是0%,然后就不知道问题出在哪了,请高手指点。。不甚感谢
PerformanceCounter _oPerformanceCounter=new PerformanceCounter("Processor","% Processor Time","_Total");float _nVal=_oPerformanceCounter.NextValue();你的代码没问题。试试LS说的,先开任务管理器再用程序看使用率