Hi ,
I have tried a lot for getting the cpu load, but seems there is no any specific mechanism for getting this. So finall developed the c# code using performance counters.
Find the snnipet here..
+++++++++++++++++++++++++++++++++++++
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;
namespace cpu_load
{
class Program
{
static void Main(string[] args)
{
System.Diagnostics.PerformanceCounter cpuusage = new System.Diagnostics.PerformanceCounter("Processor", "% Processor Time", "_Total");
cpuusage.NextValue();
Thread.Sleep(1000);
Console.WriteLine(Convert.ToInt64(cpuusage.NextValue()));
}
}
}
++++++++++++++++++++++++++++++++++++
Compile this code and run the .exe file under /debug/bin folder.
--Dinesh
I have tried a lot for getting the cpu load, but seems there is no any specific mechanism for getting this. So finall developed the c# code using performance counters.
Find the snnipet here..
+++++++++++++++++++++++++++++++++++++
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;
namespace cpu_load
{
class Program
{
static void Main(string[] args)
{
System.Diagnostics.PerformanceCounter cpuusage = new System.Diagnostics.PerformanceCounter("Processor", "% Processor Time", "_Total");
cpuusage.NextValue();
Thread.Sleep(1000);
Console.WriteLine(Convert.ToInt64(cpuusage.NextValue()));
}
}
}
++++++++++++++++++++++++++++++++++++
Compile this code and run the .exe file under /debug/bin folder.
--Dinesh
Comments
Post a Comment