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 wi开发者_Python百科ndows 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
}
It is very difficult to help you without more information but I will try to tell you how to figure out the problem yourself.
You should look in the stack trace to get the line of code that threw the error. This should show you what is going wrong.
精彩评论