I was coding on my project and wanted to debug it, but I got this error message:
Object reference not set to an instance to an object
NullReferenceExpection was unhandled
My program was working and I had this error for a few days. There I solved the problem with, I think, with typing something in my windows console. I think I reseted the Performance Counter and then it worked.
Here is the code:
public void Counter()
{
counter = new PerformanceCounter();
counter.CategoryName = "Processor";
counter.CounterName = "% Processor Time";
counter.InstanceName = "_Total";
}
public double GetCounter()
{
return counter.NextValue(); //error message is in this line
}