9

I have created a custom performance counter using the following code:

public class PerfCounter
{
    private PerformanceCounter perfCounter;

    PerfCounter(string CategoryName, string CounterName)
    {
        perfCounter = new PerformanceCounter(CategoryName, CounterName, false);
        perfCounter.BeginInit();
    }

    public void IncrementBy(long value)
    {
        perfCounter.IncrementBy(value);
    }

    public void Reset()
    {
        //what should I add here?
    }
}

Everything works fine but I don't know how to Reset the counter. Can anyone help me?

chaliasos
  • 9,659
  • 7
  • 50
  • 87
  • 2
    Perhaps this will help? http://stackoverflow.com/questions/9195851/reset-performance-counter-from-command-line –  Mar 06 '12 at 14:21

1 Answers1

12

Do this:

public void Reset()
{
    perfCounter.RawValue = 0;
}
Rian Schmits
  • 3,096
  • 3
  • 28
  • 44