C
Chris
I'm trying to do something really easy: just get the % CPU load. However, I
just get mostly 0's sprinkled with an occasional 100. I poked around on
the web for info, but all the stuff I found (I think) does what I have
below. Am I blanking out on something here?
Getting the available RAM works fine.
Code example below:
using System;
using System.Diagnostics;
namespace PerfMon
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
//Create CPU counter
PerformanceCounter cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
//Create RAM counter
//PerformanceCounter ramCounter = new PerformanceCounter();
//ramCounter.CategoryName = "Memory";
//ramCounter.CounterName = "Available MBytes";
//Display counter
int i;
for (i=0;i<100;i++)
{
Console.WriteLine(cpuCounter.NextValue().ToString());
}
Console.ReadLine();
}
}
}
just get mostly 0's sprinkled with an occasional 100. I poked around on
the web for info, but all the stuff I found (I think) does what I have
below. Am I blanking out on something here?
Getting the available RAM works fine.
Code example below:
using System;
using System.Diagnostics;
namespace PerfMon
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
//Create CPU counter
PerformanceCounter cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "Processor";
cpuCounter.CounterName = "% Processor Time";
cpuCounter.InstanceName = "_Total";
//Create RAM counter
//PerformanceCounter ramCounter = new PerformanceCounter();
//ramCounter.CategoryName = "Memory";
//ramCounter.CounterName = "Available MBytes";
//Display counter
int i;
for (i=0;i<100;i++)
{
Console.WriteLine(cpuCounter.NextValue().ToString());
}
Console.ReadLine();
}
}
}