Microsoft KB Archive/324548

= BUG: NextValue method of .NET PerformanceCounter object returns zero =

Article ID: 324548

Article Last Modified on 4/30/2004

-

APPLIES TO


 * Microsoft .NET Framework 1.0
 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework Class Libraries 1.0
 * Microsoft .NET Framework Class Libraries 1.1

-



This article was previously published under Q324548



SYMPTOMS
The NextValue method of the .NET PerformanceCounter object may return zero (0) for the following LogicalDisk or PhysicalDisk performance counters:
 * % Disk Time
 * % Disk Read Time
 * % Disk Write Time
 * % Idle Time
 * Avg. Disk Queue Length
 * Avg. Disk Read Queue Length
 * Avg. Disk Write Queue Length



CAUSE
The performance counters that are listed in the &quot;Symptoms&quot; section use the following counter types:
 * PERF_PRECISION_100NS_TIMER
 * PERF_PRECISION_TIMESTAMP
 * PERF_COUNTER_100NS_QUEUELEN_TYPE

This problem occurs because the implementation of the .NET PerformanceCounter class does not correctly handle these counter types.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.



MORE INFORMATION
The following C# sample code reproduces the problem: using System; using System.Diagnostics; using System.Threading;

public class function {   public static void Main {       float value; int i;       PerformanceCounter objPerfMon; string machineName = &quot;.&quot;; string objectName = &quot;PhysicalDisk&quot;; try {           for (i=0; i<10; i++) {                objPerfMon = new PerformanceCounter(objectName, &quot;% Disk Time&quot;, &quot;_Total&quot;, machineName); value = objPerfMon.NextValue; Thread.Sleep(100); value = objPerfMon.NextValue; Console.WriteLine(&quot;% Disk Time &quot; + value.ToString); }           for (i=0; i<10; i++) {                objPerfMon = new PerformanceCounter(objectName, &quot;% Disk Read Time&quot;, &quot;_Total&quot;, machineName); value = objPerfMon.NextValue; Thread.Sleep(100); value = objPerfMon.NextValue; Console.WriteLine(&quot;% Disk Read Time &quot; + value.ToString); }           for (i=0; i<10; i++) {                objPerfMon = new PerformanceCounter(objectName, &quot;% Disk Write Time&quot;, &quot;_Total&quot;, machineName); value = objPerfMon.NextValue; Thread.Sleep(100); value = objPerfMon.NextValue; Console.WriteLine(&quot;% Disk Write Time &quot; + value.ToString); }           for (i=0; i<10; i++) {                objPerfMon = new PerformanceCounter(objectName, &quot;% Idle Time&quot;, &quot;_Total&quot;, machineName); value = objPerfMon.NextValue; Thread.Sleep(100); value = objPerfMon.NextValue; Console.WriteLine(&quot;% Idle Time &quot; + value.ToString); }

for (i=0; i<10; i++) {                objPerfMon = new PerformanceCounter(objectName, &quot;Avg. Disk Queue Length&quot;, &quot;_Total&quot;, machineName); value = objPerfMon.NextValue; Thread.Sleep(100); value = objPerfMon.NextValue; Console.WriteLine(&quot;Avg. Disk Queue Length &quot; + value.ToString); }

for (i=0; i<10; i++) {                objPerfMon = new PerformanceCounter(objectName, &quot;Avg. Disk Read Queue Length&quot;, &quot;_Total&quot;, machineName); value = objPerfMon.NextValue; Thread.Sleep(100); value = objPerfMon.NextValue; Console.WriteLine(&quot;Avg. Disk Read Queue Length &quot; + value.ToString); }

for (i=0; i<10; i++) {                objPerfMon = new PerformanceCounter(objectName, &quot;Avg. Disk Write Queue Length&quot;, &quot;_Total&quot;, machineName); value = objPerfMon.NextValue; Thread.Sleep(100); value = objPerfMon.NextValue; Console.WriteLine(&quot;Avg. Disk Write Queue Length &quot; + value.ToString); }       }        catch (InvalidOperationException) {           Console.WriteLine(&quot;N/A&quot;); }       catch (Exception ex) {           Console.WriteLine(ex.ToString); }   } }

