Guest User

Untitled

a guest
May 8th, 2012
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. RawFraction performance counter persists its state even after deleting the performance category
  2. private PerformanceCounter mainCounter;
  3. private PerformanceCounter mainCounterBase;
  4. private string category = "TestPerformanceCounterTest";
  5. public void Test()
  6. {
  7. //Counter setup
  8.  
  9. if (PerformanceCounterCategory.Exists(category))
  10. PerformanceCounterCategory.Delete(category);
  11. if (!PerformanceCounterCategory.Exists(category))
  12. {
  13. var categoryCollection = new CounterCreationDataCollection();
  14.  
  15. var counter1 = new CounterCreationData("RawCounter1", "", PerformanceCounterType.RawFraction);
  16. var counter2 = new CounterCreationData("RawCounterBase1", "", PerformanceCounterType.RawBase);
  17. categoryCollection.Add(counter1);
  18. categoryCollection.Add(counter2);
  19.  
  20.  
  21. PerformanceCounterCategory.Create(category, "", PerformanceCounterCategoryType.SingleInstance, categoryCollection);
  22.  
  23. // Wait and wait...
  24. Thread.Sleep(TimeSpan.FromSeconds(3));
  25. }
  26. //create counters
  27. mainCounter = new PerformanceCounter(category, "RawCounter1", false);
  28. mainCounterBase = new PerformanceCounter(category, "RawCounterBase1", false);
  29. //reset values
  30. mainCounter.RawValue = 0;
  31. mainCounterBase.RawValue = 0;
  32.  
  33. //update counter
  34. mainCounter.IncrementBy(10);
  35. mainCounterBase.IncrementBy(20);
  36. **Console.WriteLine("Main counter: " +mainCounter.RawValue);//doesnt show value 50 the second time this is run**
  37. Console.WriteLine("Main counter Base: " + mainCounterBase.RawValue);
  38. Console.WriteLine("Main counter next value: " + mainCounter.NextValue());
  39. Console.WriteLine("Main counter base next value: " + mainCounterBase.NextValue());
  40. }
  41.  
  42. while (PerformanceCounterCategory.Exists(category))
  43. {
  44. PerformanceCounterCategory.Delete(category);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment