Unresponsive performance counters
If I run the c# code in example 1 the processor time never changes from 0
(which might be the inital value on my PC). But if I create two separate
counters as in example 2 (or example 3) the processor shows proper values.
In addition it takes the logical disk counter easily 60 seconds or more to
adjust to changes on the disk (copying & deleting a large file) (Windows XP
SP2) . However, perfmon suffers from the same lag, so this might well be OS
related.
Regards,
Andries
======== Example 1
PerformanceCounter myCounter = new PerformanceCounter();
while (true)
{
myCounter.CategoryName = "LogicalDisk";
myCounter.CounterName = "% Free Space";
myCounter.InstanceName = "C:";
Console.WriteLine("> " + myCounter.NextValue() );
myCounter.CategoryName = "Processor";
myCounter.CounterName = "% Processor Time";
myCounter.InstanceName = "_Total";
Console.WriteLine("> " + myCounter.NextValue() );
Thread.Sleep( 1000 );
}
======== Example 2
PerformanceCounter myCounter = new PerformanceCounter();
PerformanceCounter myCounter2 = new PerformanceCounter();
while (true)
{
myCounter.CategoryName = "LogicalDisk";
myCounter.CounterName = "% Free Space";
myCounter.InstanceName = "C:";
Console.WriteLine("> " + myCounter.NextValue() );
myCounter2.CategoryName = "Processor";
myCounter2.CounterName = "% Processor Time";
myCounter2.InstanceName = "_Total";
Console.WriteLine("> " + myCounter2.NextValue() );
Thread.Sleep( 1000 );
}
======== Example 3
PerformanceCounter myCounter = new PerformanceCounter();
PerformanceCounter myCounter2 = new PerformanceCounter();
myCounter.CategoryName = "LogicalDisk";
myCounter.CounterName = "% Free Space";
myCounter.InstanceName = "C:";
myCounter2.CategoryName = "Processor";
myCounter2.CounterName = "% Processor Time";
myCounter2.InstanceName = "_Total";
while (true)
{
Console.WriteLine("> " + myCounter.NextValue() );
Console.WriteLine("> " + myCounter2.NextValue() );
Thread.Sleep( 1000 );
}
Date:Wed, 8 Aug 2007 22:13:24 +0200
Author:
|