static void Main(string[] args) { CounterCreationDataCollection counters = new CounterCreationDataCollection(); counters.Add(new CounterCreationData("Sales", "Number of total sales", PerformanceCounterType.NumberOfItems64)); counters.Add(new CounterCreationData("Active Users", "Number of active users", PerformanceCounterType.NumberOfItems64)); counters.Add(new CounterCreationData("Sales value", "Total value of all sales", PerformanceCounterType.NumberOfItems64)); PerformanceCounterCategory.Create("MyApp Counters", "Counters describing the performance of MyApp", PerformanceCounterCategoryType.SingleInstance, counters); PerformanceCounter pc = new PerformanceCounter("MyApp Counters", "Sales", false); pc.RawValue = 7; pc.Decrement(); pc.Increment(); pc.IncrementBy(3); }
internal bool Decrement() { if (!this.Accessible) { return(false); } try { _counter.Decrement(); } catch (Exception ex) { LogException(ex); return(false); } return(true); }
static void DecrementCounter(ref PerformanceCounter counter) { if (counter != null) { try { counter.Decrement(); } #pragma warning suppress 56500 // covered by FxCOP catch (Exception exception) { if (Fx.IsFatal(exception)) { throw; } ListenerPerfCounters.TracePerformanceCounterUpdateFailure(counter.InstanceName, counter.CounterName); counter = null; } } }
private static void DoItem(PerformanceCounter c) { c.Increment(); Thread.Sleep(5); c.Decrement(); }