Getting the CPU usage generates "Category does not exist" error

Good afternoon!

The core cause of this problem is a seemingly random corruption of the pointers to the performance counters in the registry. This happens infrequently, but most often happens on Windows Server 2008 R2.

Strictly speaking the "Process" and "Processor" category should always exist by default as performance counters. If they are missing, there are possibly many other counters that are missing as well. The previous solutions would not solve the problem if the "Processor Information" counter was also corrupted as well. To resolve this definitively you can run the following command:

lodctr /R

This will repair any broken pointers to your counters. To verify this solution you can go to Server Manager -> Monitoring -> Performance Monitor -> Add ... Within this view you can view all of the currently registered performance counters. Both "Processor" and "Process" should now be available. Alternatively, you can run the following command to view the status of all of the available counters as well:

lodctr /Q

As a side note, this command should be run from an Administrative console; otherwise this process may fail with "error code: 5 (Access Denied)"


Use

new PerformanceCounter("Processor Information", "% Processor Time", "_Total");

Instead of

new PerformanceCounter("Processor", "% Processor Time", "_Total");

Tags:

C#