Exemple #1
0
        /// <summary>
        ///     Returns an array of counters in this category for the given instance.
        /// </summary>
        public PerformanceCounter[] GetCounters(string instanceName)
        {
            if (instanceName == null)
            {
                throw new ArgumentNullException(nameof(instanceName));
            }

            if (_categoryName == null)
            {
                throw new InvalidOperationException(SR.Format(SR.CategoryNameNotSet));
            }

            if (instanceName.Length != 0 && !InstanceExists(instanceName))
            {
                throw new InvalidOperationException(SR.Format(SR.MissingInstance, instanceName, _categoryName));
            }

            var counterNames = PerformanceCounterLib.GetCounters(_categoryName);
            var counters     = new PerformanceCounter[counterNames.Length];

            for (var index = 0; index < counters.Length; index++)
            {
                counters[index] = new PerformanceCounter(_categoryName, counterNames[index], instanceName, true);
            }

            return(counters);
        }