如何重置自定义性能计数器

时间:2012-03-06 14:15:31

标签: c# visual-studio-2010 performancecounter

我使用以下代码创建了自定义性能计数器:

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?
    }
}

一切正常,但我不知道如何重置计数器。任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:12)

这样做:

public void Reset()
{
    perfCounter.RawValue = 0;
}