コード例 #1
0
        private void SetCounterProperties()
        {
            var loadCounters = true;

            foreach (var property in _counterProperties)
            {
                PerformanceCounterAttribute attribute = GetPerformanceCounterAttribute(property);

                if (attribute == null)
                {
                    continue;
                }

                IPerformanceCounter counter = null;

                if (loadCounters)
                {
                    counter = LoadCounter(CategoryName, attribute.Name, isReadOnly: false);

                    if (counter == null)
                    {
                        // We failed to load the counter so skip the rest
                        loadCounters = false;
                    }
                }

                counter = counter ?? _noOpCounter;

                property.SetValue(this, counter, null);
            }
        }
コード例 #2
0
        private void SetCounterProperties(string instanceName)
        {
            bool loadCounters = true;

            foreach (var property in _counterProperties)
            {
                PerformanceCounterAttribute attribute = GetPerformanceCounterAttribute(property);

                if (attribute == null)
                {
                    continue;
                }

                IPerformanceCounter counter = null;

                if (loadCounters)
                {
                    counter = LoadCounter(CategoryName, attribute.Name, instanceName);

                    if (counter == null)
                    {
                        loadCounters = false;
                    }
                }

                counter = counter ?? _noOpCounter;

                // Initialize the counter sample
                counter.NextSample();

                property.SetValue(this, counter, null);
            }
        }