示例#1
0
        public void AddCounter(Int32 counterId, CounterType counterType)
        {
            if (m_provider == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.Perflib_InvalidOperation_NoActiveProvider, m_providerGuid));
            }
            if (!PerfProviderCollection.ValidateCounterType(counterType))
            {
                throw new ArgumentException(SR.GetString(SR.Perflib_Argument_InvalidCounterType, counterType), "counterType");
            }
            if (m_instanceCreated)
            {
                throw new InvalidOperationException(SR.GetString(SR.Perflib_InvalidOperation_AddCounterAfterInstance, m_counterSet));
            }

            lock (m_lockObject) {
                if (m_instanceCreated)
                {
                    throw new InvalidOperationException(SR.GetString(SR.Perflib_InvalidOperation_AddCounterAfterInstance, m_counterSet));
                }
                if (m_idToCounter.ContainsKey(counterId))
                {
                    throw new ArgumentException(SR.GetString(SR.Perflib_Argument_CounterAlreadyExists, counterId, m_counterSet), "CounterId");
                }

                m_idToCounter.Add(counterId, counterType);
            }
        }
示例#2
0
        /// <summary>
        /// Add non-displayable new counter to CounterSet; that is, perfmon would not display the counter.
        /// </summary>
        /// <param name="counterId">CounterId uniquely identifies the counter within CounterSet</param>
        /// <param name="counterType">One of defined CounterType values</param>
        public void AddCounter(int counterId, CounterType counterType)
        {
            if (_provider == null)
            {
                throw new InvalidOperationException(SR.Format(SR.Perflib_InvalidOperation_NoActiveProvider, _providerGuid));
            }
            if (!PerfProviderCollection.ValidateCounterType(counterType))
            {
                throw new ArgumentException(SR.Format(SR.Perflib_Argument_InvalidCounterType, counterType), nameof(counterType));
            }
            if (_instanceCreated)
            {
                throw new InvalidOperationException(SR.Format(SR.Perflib_InvalidOperation_AddCounterAfterInstance, _counterSet));
            }

            lock (_lockObject)
            {
                if (_instanceCreated)
                {
                    throw new InvalidOperationException(SR.Format(SR.Perflib_InvalidOperation_AddCounterAfterInstance, _counterSet));
                }
                if (_idToCounter.ContainsKey(counterId))
                {
                    throw new ArgumentException(SR.Format(SR.Perflib_Argument_CounterAlreadyExists, counterId, _counterSet), nameof(counterId));
                }

                _idToCounter.Add(counterId, counterType);
            }
        }
示例#3
0
 public void AddCounter(int counterId, CounterType counterType)
 {
     if (this.m_provider == null)
     {
         throw new InvalidOperationException(System.SR.GetString("Perflib_InvalidOperation_NoActiveProvider", new object[] { this.m_providerGuid }));
     }
     if (!PerfProviderCollection.ValidateCounterType(counterType))
     {
         throw new ArgumentException(System.SR.GetString("Perflib_Argument_InvalidCounterType", new object[] { counterType }), "counterType");
     }
     if (this.m_instanceCreated)
     {
         throw new InvalidOperationException(System.SR.GetString("Perflib_InvalidOperation_AddCounterAfterInstance", new object[] { this.m_counterSet }));
     }
     lock (this.m_lockObject)
     {
         if (this.m_instanceCreated)
         {
             throw new InvalidOperationException(System.SR.GetString("Perflib_InvalidOperation_AddCounterAfterInstance", new object[] { this.m_counterSet }));
         }
         if (this.m_idToCounter.ContainsKey(counterId))
         {
             throw new ArgumentException(System.SR.GetString("Perflib_Argument_CounterAlreadyExists", new object[] { counterId, this.m_counterSet }), "CounterId");
         }
         this.m_idToCounter.Add(counterId, counterType);
     }
 }