Beispiel #1
0
 internal ServicePerformanceCounters(ServiceHostBase serviceHost) : base(serviceHost)
 {
     this.Counters = new PerformanceCounter[0x27];
     for (int i = 0; i < 0x27; i++)
     {
         PerformanceCounter servicePerformanceCounter = PerformanceCounters.GetServicePerformanceCounter(ServicePerformanceCountersBase.perfCounterNames[i], this.InstanceName);
         if (servicePerformanceCounter == null)
         {
             break;
         }
         try
         {
             servicePerformanceCounter.RawValue = 0L;
             this.Counters[i] = servicePerformanceCounter;
         }
         catch (Exception exception)
         {
             if (Fx.IsFatal(exception))
             {
                 throw;
             }
             if (DiagnosticUtility.ShouldTraceError)
             {
                 TraceUtility.TraceEvent(TraceEventType.Error, 0x8003b, System.ServiceModel.SR.GetString("TraceCodePerformanceCountersFailedForService"), null, exception);
             }
             break;
         }
     }
 }
        internal ServicePerformanceCounters(ServiceHostBase serviceHost)
            : base(serviceHost)
        {
            this.Counters = new PerformanceCounter[(int)PerfCounters.TotalCounters];
            for (int i = 0; i < (int)PerfCounters.TotalCounters; i++)
            {
                PerformanceCounter counter = PerformanceCounters.GetServicePerformanceCounter(perfCounterNames[i], this.InstanceName);
                if (counter != null)
                {
                    try
                    {
                        counter.RawValue = 0;
                        this.Counters[i] = counter;
                    }
#pragma warning suppress 56500 // covered by FxCOP
                    catch (Exception e)
                    {
                        if (Fx.IsFatal(e))
                        {
                            throw;
                        }
                        if (DiagnosticUtility.ShouldTraceError)
                        {
                            TraceUtility.TraceEvent(TraceEventType.Error, TraceCode.PerformanceCountersFailedForService,
                                                    SR.GetString(SR.TraceCodePerformanceCountersFailedForService), null, e);
                        }
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
        }