
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 2.00 KB | hits: 12 | expires: Never
RawFraction performance counter persists its state even after deleting the performance category
private PerformanceCounter mainCounter;
private PerformanceCounter mainCounterBase;
private string category = "TestPerformanceCounterTest";
public void Test()
{
//Counter setup
if (PerformanceCounterCategory.Exists(category))
PerformanceCounterCategory.Delete(category);
if (!PerformanceCounterCategory.Exists(category))
{
var categoryCollection = new CounterCreationDataCollection();
var counter1 = new CounterCreationData("RawCounter1", "", PerformanceCounterType.RawFraction);
var counter2 = new CounterCreationData("RawCounterBase1", "", PerformanceCounterType.RawBase);
categoryCollection.Add(counter1);
categoryCollection.Add(counter2);
PerformanceCounterCategory.Create(category, "", PerformanceCounterCategoryType.SingleInstance, categoryCollection);
// Wait and wait...
Thread.Sleep(TimeSpan.FromSeconds(3));
}
//create counters
mainCounter = new PerformanceCounter(category, "RawCounter1", false);
mainCounterBase = new PerformanceCounter(category, "RawCounterBase1", false);
//reset values
mainCounter.RawValue = 0;
mainCounterBase.RawValue = 0;
//update counter
mainCounter.IncrementBy(10);
mainCounterBase.IncrementBy(20);
**Console.WriteLine("Main counter: " +mainCounter.RawValue);//doesnt show value 50 the second time this is run**
Console.WriteLine("Main counter Base: " + mainCounterBase.RawValue);
Console.WriteLine("Main counter next value: " + mainCounter.NextValue());
Console.WriteLine("Main counter base next value: " + mainCounterBase.NextValue());
}
while (PerformanceCounterCategory.Exists(category))
{
PerformanceCounterCategory.Delete(category);
}