コード例 #1
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);
            }
        }