Sirisha wrote:
Quote:
I am using the following code to get the CPU usage
>
PerformanceCounter myCounter;
myCounter = new PerformanceCounter();
>
myCounter.CategoryName = "Processor";
myCounter.CounterName = "% Processor Time";
myCounter.InstanceName = "_Total";
>
for(int i=0; i < 20; i++)
myCounter.NextValue();
>
I ran this progam i am seeing values 0 or 100%, but when i see the task
manager the CPU usage is 6 to 22 %.
First of all, 20 reptitions aren't going to show you anything. You need
to take samples over 20,000, 200,000, or 2,000,000 reptitions, or
something of that order.
Second, the task manager is showing you an average CPU usage over
slices of time. Your program will finish in the blink of an eye and so
won't really register on the task manager's CPU monitor.
Third, since your program is doing nothing but processing, clearly
_while it's running_ it's using up 100% of the CPU, so your results are
not surprising.