A small search on the Internet, and I found this thing called " Performance Counters ", you can either provide the counter data, or use the counter data using This. In your case, I believe you want to read data from performance counters.
You can use performance data using either the registry interface or the PDH interface. The PDH interface is easier to use than the registry interface, and is recommended for most performance data collection tasks. The PDH interface is essentially an abstraction of the higher level of functionality provided by the registry interface.
Here is another article from Microsoft on Monitoring Context Switches .
source share