110,477
社区成员
发帖
与我相关
我的任务
分享
public partial class Form1 : Form
{
PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
double cpu = getCurrentCpuUsage();
double Freemem = getAvailableRAM();
double usedMem = getCommitedRAM();
}
public double getCurrentCpuUsage()
{
return cpuCounter.NextValue();
}
/*
Call this method every time you need to get
the amount of the available RAM in Mb
*/
public double getAvailableRAM()
{
PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available Bytes");
return ramCounter.NextValue();
}
/*
Call this method every time you need to get
the amount of the available RAM in Mb
*/
public double getCommitedRAM()
{
PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Committed Bytes");
return ramCounter.NextValue();
}
}