110,536
社区成员
发帖
与我相关
我的任务
分享
PerformanceCounter cpuCounter;
PerformanceCounter ramCounter;
cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
ramCounter = new PerformanceCounter("Memory", "Available MBytes");
public string getCurrentCpuUsage(){
cpuCounter.NextValue()+"%";
}
public string getAvailableRAM(){
ramCounter.NextValue()+"MB";
}
listBox1.Items.Clear();
Process[] ps = Process.GetProcesses();
for (int i = 0; i < ps.Length; i++)
{
this.listBox1.Items.Add(ps[i].ProcessName + "------>" + ps[i].Id);
}
this.listBox1.SelectedIndex = indexForUser;
lblProcess.Text = "进程数:" + ps.Length;