我使用以下代码创建了自定义性能计数器:
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?
}
}
一切正常,但我不知道如何重置计数器。任何人都可以帮助我吗?
答案 0 :(得分:12)
这样做:
public void Reset()
{
perfCounter.RawValue = 0;
}