Wednesday, February 1, 2017

Perfmon error- Performance Counter Input string was not in a correct format C#

Issue:


Here is my code
float cpuLoad = 0;

try{
    MessageBox.Show("Running");

    //CPU Load
    PerformanceCounter cpuCounter = new PerformanceCounter();
    cpuCounter.CategoryName = "Processor";
    cpuCounter.CounterName = "% Processor Time";
    cpuCounter.InstanceName = "_Total";

    MessageBox.Show("Performance Counter Created");

    cpuLoad = cpuCounter.NextValue(); // Here exception is raised
}
catch(Exception ex) { MessageBox.Show(ex.Message); }
I have a try and catch around it and here is the exception it throws Input string was not in a correct format.

Solution:
try in cmd> lodctr /r
If above command is successful then all of your issues related to perfmon are resolved.
In case above command is not successful then try following:
Open perfmon-> Go to File-> Options-> Delete store files.
Now again try "lodctr /r". This should work now.

No comments:

Post a Comment