有些指标需要至少调用两次(第一次初始话);
float cpuStr = pcCpuLoad.NextValue();
cpuStr = pcCpuLoad.NextValue(); // <--再调用一次。
float cpuStr = pcCpuLoad.NextValue();
cpuStr = pcCpuLoad.NextValue(); // <--再调用一次。
解决方案 »
- C# 连接InterBase出错!!!
- 求助一个继承自Dictionary的自定义类的深度克隆问题
- Random random=new Random(); random.next(9);能返回9吗?
- C#连接sql数据库后,select语句的执行
- TreeView 中为什么没有显示结果。
- 点击datagridview列进行排序,界面上行的顺序变了,datagridview.datasource还是以前的顺序,怎样让它同时改变啊?
- DataList里TextBox取值
- DataGrid中如何得到选定行的记录
- 请教winform一个小程序
- 求助:自定义表和普通数据表 合并查询
- 怎么把视频缩略图显示成列表(wpf)
- C# DLLImport 的方法参数是一个 typedef struct {...}IDCARD_ALL; 结构的地址 IDCARD_ALL & 调用后没数据
//点击开始按钮
private void btnStart_Click(object sender, EventArgs e)
{
PerformanceCounter pcCpuLoad = new PerformanceCounter("Processor", "% Processor Time", "_Total");
Thread newThread = new Thread(GetCpuLoad);
newThread.Start(pcCpuLoad);//启动一个新线程读取CPU占用率
} //读取CPU占用率并显示
private void GetCpuLoad(object obj)
{
PerformanceCounter pcCpuLoad = (PerformanceCounter)obj;
SetLabelTextDelegate setLabelTextDelegate = new SetLabelTextDelegate(SetLabelText);
while (true) {
Thread.Sleep(1000);//每隔一秒读取一次值
float cpuLoad = pcCpuLoad.NextValue();
this.Invoke(setLabelTextDelegate, new object[] { cpuLoad + "%" });//UI线程显示结果
}
} delegate void SetLabelTextDelegate(string text);
private void SetLabelText(string text)//label1显示CPU占用率
{
label1.Text = text;
}