当前位置: 首页>>代码示例>>C#>>正文


C# PerformanceCounter.RemoveInstance方法代码示例

本文整理汇总了C#中System.Diagnostics.PerformanceCounter.RemoveInstance方法的典型用法代码示例。如果您正苦于以下问题:C# PerformanceCounter.RemoveInstance方法的具体用法?C# PerformanceCounter.RemoveInstance怎么用?C# PerformanceCounter.RemoveInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Diagnostics.PerformanceCounter的用法示例。


在下文中一共展示了PerformanceCounter.RemoveInstance方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Dispose

		private static void Dispose(PerformanceCounter counter)
		{
			if (null != counter)
			{
				counter.RemoveInstance();
				counter.Dispose();
			}
		}
开发者ID:Galigator,项目名称:db4o,代码行数:8,代码来源:NetworkingCounters.cs

示例2: ReleasePerformanceCounter

        internal static void ReleasePerformanceCounter(ref PerformanceCounter counter)
        {
            if (counter != null)
            {
                try
                {
                    counter.RemoveInstance();
                    counter = null;
                }
#pragma warning suppress 56500 // covered by FxCOP
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                }
            }
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:19,代码来源:PerformanceCounters.cs

示例3: Dispose

 /// <summary>
 /// Dispose performance counter instance
 /// </summary>
 public void Dispose()
 {
     if (_initialized)
     {
         lock (_lockObject)
         {
             // If performance counter instance exists, remove it here.
             if (_initialized)
             {
                 // We can assume here that performance counter catagory, instance and first counter in the cointerList exist as _initialized is set to true.
                 using (PerformanceCounter pcRemove = new PerformanceCounter())
                 {
                     pcRemove.CategoryName = PerformanceCounters.ShardManagementPerformanceCounterCategory;
                     pcRemove.CounterName = counterList.First().CounterDisplayName;
                     pcRemove.InstanceName = _instanceName;
                     pcRemove.InstanceLifetime = PerformanceCounterInstanceLifetime.Process;
                     pcRemove.ReadOnly = false;
                     // Removing instance using a single counter removes all counters for that instance.
                     pcRemove.RemoveInstance();
                 }
             }
             _initialized = false;
         }
     }
 }
开发者ID:CrossPoint,项目名称:elastic-db-tools,代码行数:28,代码来源:PerfCounterInstance.cs

示例4: GetPerformanceCounterInternal

        static internal PerformanceCounter GetPerformanceCounterInternal(string categoryName, string perfCounterName, string instanceName, PerformanceCounterInstanceLifetime instanceLifetime)
        {
            PerformanceCounter counter = null;
            try
            {
                counter = new PerformanceCounter();
                counter.CategoryName = categoryName;
                counter.CounterName = perfCounterName;
                counter.InstanceName = instanceName;
                counter.ReadOnly = false;
                counter.InstanceLifetime = instanceLifetime;

                // We now need to access the counter raw data to
                // force the counter object to be initialized.  This
                // will force any exceptions due to mis-installation
                // of counters to occur here and be traced appropriately.
                try
                {
                    long rawValue = counter.RawValue;
                }
                catch (InvalidOperationException)
                {
                    counter = null;
                    throw;
                }
                catch (SecurityException securityException)
                {
                    // Cannot access performance counter due to partial trust scenarios
                    // Disable the default performance counters' access otherwise
                    // in PT the service will be broken
                    PerformanceCounters.scope = PerformanceCounterScope.Off;

                    DiagnosticUtility.TraceHandledException(new SecurityException(SR.GetString(
                                SR.PartialTrustPerformanceCountersNotEnabled), securityException), TraceEventType.Warning);
                    
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                        new SecurityException(SR.GetString(
                                SR.PartialTrustPerformanceCountersNotEnabled)));
                }
            }
#pragma warning suppress 56500 // covered by FxCOP
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                if (null != counter)
                {
                    if (!counter.ReadOnly)
                    {
                        try
                        {
                            counter.RemoveInstance();
                        }
                        // Already inside a catch block for a failure case
                        // ok to ---- any exceptions here and trace the
                        // original failure.
#pragma warning suppress 56500 // covered by FxCOP
                        catch (Exception e1)
                        {
                            if (Fx.IsFatal(e1))
                            {
                                throw;
                            }
                        }
                    }

                    counter = null;
                }
                bool logEvent = true;
                if (categoryName == PerformanceCounterStrings.SERVICEMODELSERVICE.ServicePerfCounters)
                {
                    if (serviceOOM == false)
                    {
                        serviceOOM = true;
                    }
                    else
                    {
                        logEvent = false;
                    }
                }
                else if (categoryName == PerformanceCounterStrings.SERVICEMODELOPERATION.OperationPerfCounters)
                {
                    if (operationOOM == false)
                    {
                        operationOOM = true;
                    }
                    else
                    {
                        logEvent = false;
                    }
                }
                else if (categoryName == PerformanceCounterStrings.SERVICEMODELENDPOINT.EndpointPerfCounters)
                {
                    if (endpointOOM == false)
                    {
                        endpointOOM = true;
                    }
//.........这里部分代码省略.........
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:101,代码来源:PerformanceCounters.cs

示例5: ObjectsInReferenceSystemCounterFor

            private PerformanceCounter ObjectsInReferenceSystemCounterFor(IObjectContainer container)
            {
                if (_objectsCounter == null)
                {
                    _objectsCounter = Db4oPerformanceCounters.CounterFor(PerformanceCounterSpec.ObjectReferenceCount,
                        container, false);
                    var eventRegistry = EventRegistryFactory.ForObjectContainer(container);
                    eventRegistry.Closing += delegate
                    {
                        _objectsCounter.RemoveInstance();
                        _objectsCounter.Dispose();
                    };
                }

                return _objectsCounter;
            }
开发者ID:masroore,项目名称:db4o,代码行数:16,代码来源:ReferenceSystemMonitoringSupport.cs


注:本文中的System.Diagnostics.PerformanceCounter.RemoveInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。