I'm working on a project that requires monitoring of the % of cpu in use. It has to be on both Mac and Windows, so I'm using Mono and Xamarin.
The code I'm using to get this is (this is a test, but the counter is the same):
var cpuCounter = new PerformanceCounter
{
CategoryName = "Processor",
CounterName = "% Processor Time",
InstanceName = "_Total"
};
cpuCounter.NextValue ();
Thread.Sleep (1000);
for (var i = 0; i < 50; i++) {
Console.WriteLine (cpuCounter.NextValue());
Thread.Sleep (1000);
}
On a pc, this returns what the Task Manager shows. On a mac, this returns 100 on every tick, even when the activity monitor shows differently.
I've tried googling and nothing seems to work.
Ideas?