performance counter problem

  • Thread starter Thread starter Dirk Reske
  • Start date Start date
sorry...

following code:
PerformanceCounterCategory cat = new PerformanceCounterCategory("Process");

foreach (string instance in cat.GetInstanceNames())
{
PerformanceCounter counter = new PerformanceCounter("Process","%
Processor Time",instance);
this.listBox1.Items.Add(instance + ":" + counter.NextValue());
}

why does counter.NextValue() allways returns 0??
 
...
foreach (string instance in cat.GetInstanceNames())
{
PerformanceCounter counter =
new PerformanceCounter("Process","%Processor Time",instance);
this.listBox1.Items.Add(instance + ":" + counter.NextValue());
}

why does counter.NextValue() allways returns 0??

"If the calculated value of a counter depends on two counter reads, the
first read returns 0.0." [from documentation]

Perhaps you're really looking for counter.RawValue?

// Bjorn A
 
can someone give some example code, how I can read out the cpu usage of each
running process?
Its in the PerformanceCounter Category "Process"

thx

Bjorn Abelli said:
...
foreach (string instance in cat.GetInstanceNames())
{
PerformanceCounter counter =
new PerformanceCounter("Process","%Processor Time",instance);
this.listBox1.Items.Add(instance + ":" + counter.NextValue());
}

why does counter.NextValue() allways returns 0??

"If the calculated value of a counter depends on two counter reads, the
first read returns 0.0." [from documentation]

Perhaps you're really looking for counter.RawValue?

// Bjorn A
 
Back
Top