Hi All,
I'm finding that calling NextValue() on a PerformanceCounter is extremely slow. I say slow, because when I add the exact same counters (as my code uses) to perfmon, the sampling takes place every second without issue. To sample the same set of counters (instances of the Thread/Processor Time counter), my code takes 40 seconds+.
My code, in its simplest form, is doing this:
private void Foo()
{
PerformanceCounter c = new PerformanceCounter();
c.MachineName = "AServer";
c.CategoryName = "Thread";
c.CounterName = "% Processor Time";
foreach (instance k in col) //about 60ish...
{
c.InstanceName = k.InstanceName;
c.NextValue(); //is assigned to simple var
}
}
(And yes, I realise I should be calling NextValue twice initially).
As I mentioned, the same set of 60ish counters in perfmon sample quite happily. Am I doing something stupid, or is there a quicker way to "batch" sample instances?
Thanks,
Rob