2012-03-06 33 views
9

我曾嘗試使用下面的代碼創建一個自定義的性能計數器:如何重置自定義的性能計數器

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

一切工作正常,但我不知道如何重置計數器。誰能幫我?

+2

或許這將幫助? http://stackoverflow.com/questions/9195851/reset-performance-counter-from-command-line – Freddy 2012-03-06 14:21:09

回答

13

這樣做:

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

謝謝,這工作。 – Schaliasos 2012-03-06 14:28:15

+0

不客氣:-) – 2012-03-06 15:09:55

相關問題