Whats wrong with this code

  • Thread starter Thread starter Tamar Solutions
  • Start date Start date
Razzie said:
would help if we'd know what error you are getting :)

Hi - Sorry... as below

An unhandled exception of type 'System.Management.ManagementException'
occurred in system.management.dll

Additional information: Invalid parameter
 
Well, the error is in ".NET CLR MEMORY". I have no idea what kind of class
it is (if it is a custom class or comes in the framework) but you might
check documentation on the class for valid parameters.
 
Your WMI class path is wrong ( or you are confusing performance counter
object names with WMI class paths).
The class you are looking for is
"Win32_PerfFormattedData_NETFramework_NETCLRMemory" and an instance of this
class is something like:
Win32_PerfFormattedData_NETFramework_NETCLRMemory.Name
="ManagedProgramNameHere"

Following sample dumps all currently running managed apps. and show their
GC2 heap usage.

using System;
using System.Management;
class App {
public static void Main() {
SelectQuery query = new
SelectQuery("Win32_PerfFormattedData_NETFramework_NETCLRMemory");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject mo in searcher.Get()) {
Console.WriteLine("{0} ",mo["Name"]);
using(ManagementObject o = new
ManagementObject(mo["__RelPath"].ToString()))
{
o.Get();
Console.WriteLine("GC2 heapsize = " + o["Gen2heapsize"] + " bytes");
}
}
}
}


Willy.
 
Back
Top