NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Retrieving All Counters in a Category

You can use the ReadCategory method to quickly retrieve a list of all of the counters or instances in a specific category. Each time you request the return of a counter from a category by creating an instance of a PerformanceCounter object, setting it to an existing counter, and retrieving a value, the entire category is read and the requested counter is retrieved. This means that if you request five different counters from a category that contains 20 counters, the system reads the whole category five times, searching for each counter separately. Using ReadCategory, you get the same data but the category is read only once.

Note   The ReadCategory method does not take parameters – instead it returns the counters in the parent category for the current performance counter instance. That is, if you have an instance of the PerformanceCounter component configured to interact with the Processor category, calling ReadCategory on that component returns the counters in the Processor category.

The ReadCategory method returns a CountersData array that contains the counters in the category. You can use the Item property to work with the contents of the array.

To retrieve the counters in a category

  1. Create a PerformanceCounter object and configure it so that it points to the desired category. For details, see Creating PerformanceCounter Components  or Configuring PerformanceCounter Components .
  2. Create an array of type CountersData to contain the resulting category list.
  3. Call the ReadCategory method and specify the desired category as a parameter.
  4. Set the results to the array.
The following example shows how to retrieve all of the counters in the Orders category:
[Visual Basic]
Dim myctr as New PerformanceCounter
myctr.Category = "Orders"
Dim processorObject as CountersData
processorObject = myctr.ReadCategory("Processor")
[C#]
PerformanceCounter myctr = new PerformanceCounter();
myctr.Category = "Orders";
CountersData processorObject;
processorObject = myctr.ReadCategory("Processor");

See Also

Performance Counter Value Retrieval  | Creating PerformanceCounter Components  | Configuring PerformanceCounter Components