读书人

C#小疑点?

发布时间: 2012-01-16 23:36:51 作者: rapoo

C#小问题??在线等....
一个监视cpu使用情况的小程序,可以运行,但没有显示cpu的使用情况.也没有报错,添加了performanceCounter1控件属性设置为CategoryName=Processor.
ConunterName=%Processor Time. InstanceName=_Total和time1控件,属性设置为Interval=10000.这是怎么回事呀??先谢大家了.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace cpu
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void timer1_Tick(object sender, EventArgs e)
{
progressBar1.Value = (int)(performanceCounter1.NextValue());
label1.Text = "Processor Time: " + progressBar1.Value.ToString() + "% ";

}

}
}



[解决办法]
timer 控件的Enabled 属性设置为 true
[解决办法]
另外你的Interval=10000 是10秒更新一下, 设置小一点
容易看效果

读书人网 >C#

热点推荐