FIX: PerformanceCounter Class Keeps Remote Registry Handle Open (328369)



The information in this article applies to:

  • Microsoft .NET Framework 1.0 SP2

This article was previously published under Q328369

SYMPTOMS

When you use the PerformanceCounter class to retrieve performance data from a remote computer, and the remote computer is restarted, you may receive an error message that states that the handle is not valid.

RESOLUTION

A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next Microsoft .NET Framework service pack that contains this hotfix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the fix. For a complete list of Microsoft Product Support Services phone numbers and information about support costs, visit the following Microsoft Web site:NOTE: In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The typical support costs will apply to additional support questions and issues that do not qualify for the specific update in question.

The English version of this fix has the file attributes (or later) that are listed in the following table. The dates and times for these files are listed in coordinated universal time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.
   Date          Version        Size        File name
   ---------------------------------------------------
   30-Aug-2002   1.0.3705.355   1,171,456   System.dll
				

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce the Behavior

To reproduce this problem, follow these steps:
  1. Paste the following code in a new file named Test.cs. Replace Remote_Computer_Name with the name of the remote computer that has the performance counters to which you want to gain access.
    using System;
    using System.Diagnostics;
    
    
    class PerfmonProbs{
       static void Main() 
       {
       string machine = "<Remote_Computer_Name>";
       long result;
       Console.WriteLine("About to connect to " + machine + ". 
               You need to have ADMIN priviliges on it.");
       Console.WriteLine("Press [ENTER] to continue");
       Console.ReadLine();
       PerformanceCounter counter1 = new PerformanceCounter("Processor",
               "Interrupts/sec", "_Total", machine );
       result = (long)counter1.NextValue();
       Console.WriteLine("Number of interrupts per second on machine " + machine + 
               " is " + result);
       counter1.Close();
       counter1.Dispose();
       counter1 = null;
       Console.WriteLine("Now reboot the remote server, wait a couple of minutes after it 
               is back up, and then press [ENTER]");
       Console.ReadLine();
       Console.WriteLine("About to try to read perf data again.");
       Console.WriteLine("Press [ENTER] to continue");
       Console.ReadLine();
       for (int i = 0;i++<5;){
          try {
             Console.WriteLine("Attempt " + i.ToString());
             counter1 = new PerformanceCounter("Processor", "Interrupts/sec",
                        "_Total", machine );
             result = (long)counter1.NextValue();
             Console.WriteLine("Success:" + result.ToString());
             }
             catch (Exception e)
             {
                Console.WriteLine(e.Message);
                Console.WriteLine("at");
                Console.WriteLine(e.StackTrace);
             }
    
          }
    }
    }
    
    					
  2. Compile the code at a command prompt by using the command CSC TEST.CS. (You must verify that your PATH environment variable gives you access to the C# compiler, Csc.exe.)
  3. Run the Test.exe program that you created in step 2, and then follow the onscreen instructions.

    The problem occurs after the remote computer has restarted. The exception error is reported when the program tries to gain access to the performance counter on the remote computer.

Modification Type:MinorLast Reviewed:10/11/2005
Keywords:kbHotfixServer kbQFE kbbug kberrmsg kbfix kbNetFrame100preSP3fix kbQFE KB328369