Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        internal bool Decrement()
        {
            if (!this.Accessible)
            {
                return(false);
            }

            try
            {
                _counter.Decrement();
            }
            catch (Exception ex)
            {
                LogException(ex);
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        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;
                }
            }
        }
Exemplo n.º 4
0
 private static void DoItem(PerformanceCounter c)
 {
     c.Increment();
     Thread.Sleep(5);
     c.Decrement();
 }