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
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");
Performance Counter Value Retrieval | Creating PerformanceCounter Components | Configuring PerformanceCounter Components