示例#1
0
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (m_counters != null)
         {
             m_counters.Dispose();
             m_counters = null;
         }
     }
     unsafe {
         if (m_nativeInst != null)
         {
             if (Interlocked.Exchange(ref m_active, 0) != 0)
             {
                 if (m_nativeInst != null)
                 {
                     lock (m_counterSet) {
                         if (m_counterSet.m_provider != null)
                         {
                             uint Status = UnsafeNativeMethods.PerfDeleteInstance(m_counterSet.m_provider.m_hProvider, m_nativeInst);
                         }
                         m_nativeInst = null;
                     }
                 }
             }
         }
     }
 }
        internal unsafe CounterSetInstance(CounterSet counterSetDefined, string instanceName)
        {
            if (counterSetDefined == null)
            {
                throw new ArgumentNullException(nameof(counterSetDefined));
            }
            if (instanceName == null)
            {
                throw new ArgumentNullException(nameof(instanceName));
            }
            if (instanceName.Length == 0)
            {
                throw new ArgumentException(SR.Perflib_Argument_EmptyInstanceName, nameof(instanceName));
            }

            _counterSet = counterSetDefined;
            _instName   = instanceName;

            Debug.Assert(sizeof(Interop.PerfCounter.PerfCounterSetInstanceStruct) == 32);

            _nativeInst = Interop.PerfCounter.PerfCreateInstance(
                _counterSet._provider._hProvider, ref _counterSet._counterSet, _instName, 0);
            int Status = (int)((_nativeInst != null) ? Interop.Errors.ERROR_SUCCESS : Marshal.GetLastWin32Error());

            if (_nativeInst != null)
            {
                Counters = new CounterSetInstanceCounterDataSet(this);
            }
            else
            {
                // ERROR_INVALID_PARAMETER,
                // ERROR_NOT_FOUND (cannot find installed CounterSet),
                // ERROR_ALREADY_EXISTS,
                // ERROR_NOT_ENOUGH_MEMORY

                switch (Status)
                {
                case (int)Interop.Errors.ERROR_ALREADY_EXISTS:
                    throw new ArgumentException(SR.Format(SR.Perflib_Argument_InstanceAlreadyExists, _instName, _counterSet._counterSet), nameof(instanceName));

                case (int)Interop.Errors.ERROR_NOT_FOUND:
                    throw new InvalidOperationException(SR.Format(SR.Perflib_InvalidOperation_CounterSetNotInstalled, _counterSet._counterSet));

                case (int)Interop.Errors.ERROR_INVALID_PARAMETER:
                    if (_counterSet._instType == CounterSetInstanceType.Single)
                    {
                        throw new ArgumentException(SR.Format(SR.Perflib_Argument_InvalidInstance, _counterSet._counterSet), nameof(instanceName));
                    }
                    else
                    {
                        throw new Win32Exception(Status);
                    }

                default:
                    throw new Win32Exception(Status);
                }
            }

            _active = 1;
        }
示例#3
0
        internal CounterSetInstance(CounterSet counterSetDefined, String instanceName)
        {
            if (counterSetDefined == null)
            {
                throw new ArgumentNullException("counterSetDefined");
            }
            if (instanceName == null)
            {
                throw new ArgumentNullException("InstanceName");
            }
            if (instanceName.Length == 0)
            {
                throw new ArgumentException(SR.GetString(SR.Perflib_Argument_EmptyInstanceName), "InstanceName");
            }

            m_counterSet = counterSetDefined;
            m_instName   = instanceName;
            unsafe {
                m_nativeInst = UnsafeNativeMethods.PerfCreateInstance(
                    m_counterSet.m_provider.m_hProvider, ref m_counterSet.m_counterSet, m_instName, 0);
                int Status = (int)((m_nativeInst != null) ? UnsafeNativeMethods.ERROR_SUCCESS : Marshal.GetLastWin32Error());
                if (m_nativeInst != null)
                {
                    m_counters = new CounterSetInstanceCounterDataSet(this);
                }
                else
                {
                    // ERROR_INVALID_PARAMETER,
                    // ERROR_NOT_FOUND (cannot find installed CounterSet),
                    // ERROR_ALREADY_EXISTS,
                    // ERROR_NOT_ENOUGH_MEMORY

                    switch (Status)
                    {
                    case (int)UnsafeNativeMethods.ERROR_ALREADY_EXISTS:
                        throw new ArgumentException(SR.GetString(SR.Perflib_Argument_InstanceAlreadyExists, m_instName, m_counterSet.m_counterSet), "InstanceName");

                    case (int)UnsafeNativeMethods.ERROR_NOT_FOUND:
                        throw new InvalidOperationException(SR.GetString(SR.Perflib_InvalidOperation_CounterSetNotInstalled, m_counterSet.m_counterSet));

                    case (int)UnsafeNativeMethods.ERROR_INVALID_PARAMETER:
                        if (m_counterSet.m_instType == CounterSetInstanceType.Single)
                        {
                            throw new ArgumentException(SR.GetString(SR.Perflib_Argument_InvalidInstance, m_counterSet.m_counterSet), "InstanceName");
                        }
                        else
                        {
                            throw new Win32Exception(Status);
                        }

                    default:
                        throw new Win32Exception(Status);
                    }
                }
            }

            m_active = 1;
        }
        internal CounterSetInstance(CounterSet counterSetDefined, String instanceName) {
            if (counterSetDefined == null) {
                throw new ArgumentNullException("counterSetDefined");
            }
            if (instanceName == null) {
                throw new ArgumentNullException("InstanceName");
            }
            if (instanceName.Length == 0) {
                throw new ArgumentException(SR.GetString(SR.Perflib_Argument_EmptyInstanceName), "InstanceName");
            }

            m_counterSet = counterSetDefined;
            m_instName   = instanceName;
            unsafe {
                m_nativeInst = UnsafeNativeMethods.PerfCreateInstance(
                        m_counterSet.m_provider.m_hProvider, ref m_counterSet.m_counterSet, m_instName, 0);
                int Status = (int) ((m_nativeInst != null) ? UnsafeNativeMethods.ERROR_SUCCESS : Marshal.GetLastWin32Error());
                if (m_nativeInst != null) {
                    m_counters = new CounterSetInstanceCounterDataSet(this);
                }
                else {
                    // ERROR_INVALID_PARAMETER,
                    // ERROR_NOT_FOUND (cannot find installed CounterSet),
                    // ERROR_ALREADY_EXISTS,
                    // ERROR_NOT_ENOUGH_MEMORY

                    switch (Status) {
                        case (int) UnsafeNativeMethods.ERROR_ALREADY_EXISTS:
                            throw new ArgumentException(SR.GetString(SR.Perflib_Argument_InstanceAlreadyExists, m_instName, m_counterSet.m_counterSet), "InstanceName");

                        case (int) UnsafeNativeMethods.ERROR_NOT_FOUND:
                            throw new InvalidOperationException( SR.GetString(SR.Perflib_InvalidOperation_CounterSetNotInstalled, m_counterSet.m_counterSet));

                        case (int) UnsafeNativeMethods.ERROR_INVALID_PARAMETER:
                            if (m_counterSet.m_instType == CounterSetInstanceType.Single) {
                                throw new ArgumentException(SR.GetString(SR.Perflib_Argument_InvalidInstance, m_counterSet.m_counterSet), "InstanceName");
                            }
                            else {
                                throw new Win32Exception(Status);
                            }

                        default:
                            throw new Win32Exception(Status);
                    }
                }
            }

            m_active = 1;
        }
        internal unsafe CounterSetInstance(CounterSet counterSetDefined, string instanceName)
        {
            if (counterSetDefined == null)
            {
                throw new ArgumentNullException("counterSetDefined");
            }
            if (instanceName == null)
            {
                throw new ArgumentNullException("InstanceName");
            }
            if (instanceName.Length == 0)
            {
                throw new ArgumentException(System.SR.GetString("Perflib_Argument_EmptyInstanceName"), "InstanceName");
            }
            this.m_counterSet = counterSetDefined;
            this.m_instName   = instanceName;
            this.m_nativeInst = Microsoft.Win32.UnsafeNativeMethods.PerfCreateInstance(this.m_counterSet.m_provider.m_hProvider, ref this.m_counterSet.m_counterSet, this.m_instName, 0);
            int error = (this.m_nativeInst != null) ? 0 : Marshal.GetLastWin32Error();

            if (this.m_nativeInst != null)
            {
                this.m_counters = new CounterSetInstanceCounterDataSet(this);
            }
            else
            {
                switch (error)
                {
                case 0x57:
                    if (this.m_counterSet.m_instType == CounterSetInstanceType.Single)
                    {
                        throw new ArgumentException(System.SR.GetString("Perflib_Argument_InvalidInstance", new object[] { this.m_counterSet.m_counterSet }), "InstanceName");
                    }
                    throw new Win32Exception(error);

                case 0xb7:
                    throw new ArgumentException(System.SR.GetString("Perflib_Argument_InstanceAlreadyExists", new object[] { this.m_instName, this.m_counterSet.m_counterSet }), "InstanceName");

                case 0x490:
                    throw new InvalidOperationException(System.SR.GetString("Perflib_InvalidOperation_CounterSetNotInstalled", new object[] { this.m_counterSet.m_counterSet }));
                }
                throw new Win32Exception(error);
            }
            this.m_active = 1;
        }
 private unsafe void Dispose(bool disposing)
 {
     if (disposing && (this.m_counters != null))
     {
         this.m_counters.Dispose();
         this.m_counters = null;
     }
     if (((this.m_nativeInst != null) && (Interlocked.Exchange(ref this.m_active, 0) != 0)) && (this.m_nativeInst != null))
     {
         lock (this.m_counterSet)
         {
             if (this.m_counterSet.m_provider != null)
             {
                 Microsoft.Win32.UnsafeNativeMethods.PerfDeleteInstance(this.m_counterSet.m_provider.m_hProvider, this.m_nativeInst);
             }
             this.m_nativeInst = null;
         }
     }
 }
示例#7
0
 private unsafe void Dispose(bool disposing)
 {
     if (disposing && (this.m_counters != null))
     {
         this.m_counters.Dispose();
         this.m_counters = null;
     }
     if (((this.m_nativeInst != null) && (Interlocked.Exchange(ref this.m_active, 0) != 0)) && (this.m_nativeInst != null))
     {
         lock (this.m_counterSet)
         {
             if (this.m_counterSet.m_provider != null)
             {
                 Microsoft.Win32.UnsafeNativeMethods.PerfDeleteInstance(this.m_counterSet.m_provider.m_hProvider, this.m_nativeInst);
             }
             this.m_nativeInst = null;
         }
     }
 }
示例#8
0
        internal unsafe CounterSetInstance(CounterSet counterSetDefined, string instanceName)
        {
            if (counterSetDefined == null)
            {
                throw new ArgumentNullException("counterSetDefined");
            }
            if (instanceName == null)
            {
                throw new ArgumentNullException("InstanceName");
            }
            if (instanceName.Length == 0)
            {
                throw new ArgumentException(System.SR.GetString("Perflib_Argument_EmptyInstanceName"), "InstanceName");
            }
            this.m_counterSet = counterSetDefined;
            this.m_instName = instanceName;
            this.m_nativeInst = Microsoft.Win32.UnsafeNativeMethods.PerfCreateInstance(this.m_counterSet.m_provider.m_hProvider, ref this.m_counterSet.m_counterSet, this.m_instName, 0);
            int error = (this.m_nativeInst != null) ? 0 : Marshal.GetLastWin32Error();
            if (error == 0)
            {
                this.m_counters = new CounterSetInstanceCounterDataSet(this);
            }
            else
            {
                switch (error)
                {
                    case 0x57:
                        if (this.m_counterSet.m_instType == CounterSetInstanceType.Single)
                        {
                            throw new ArgumentException(System.SR.GetString("Perflib_Argument_InvalidInstance", new object[] { this.m_counterSet.m_counterSet }), "InstanceName");
                        }
                        throw new Win32Exception(error);

                    case 0xb7:
                        throw new ArgumentException(System.SR.GetString("Perflib_Argument_InstanceAlreadyExists", new object[] { this.m_instName, this.m_counterSet.m_counterSet }), "InstanceName");

                    case 0x490:
                        throw new InvalidOperationException(System.SR.GetString("Perflib_InvalidOperation_CounterSetNotInstalled", new object[] { this.m_counterSet.m_counterSet }));
                }
                throw new Win32Exception(error);
            }
            this.m_active = 1;
        }
 private void Dispose(bool disposing) {
     if (disposing) {
         if (m_counters != null) {
             m_counters.Dispose();
             m_counters = null;
         }
     }
     unsafe {
         if (m_nativeInst != null) {
             if (Interlocked.Exchange(ref m_active, 0) != 0) {
                 if (m_nativeInst != null) {
                     lock(m_counterSet) {
                         if (m_counterSet.m_provider != null) {
                             uint Status = UnsafeNativeMethods.PerfDeleteInstance(m_counterSet.m_provider.m_hProvider, m_nativeInst);
                         }
                         m_nativeInst = null;
                     }
                 }
             }
         }
     }            
 }