本文整理汇总了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();
}
}
示例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;
}
}
}
}
示例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;
}
}
}
示例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;
}
//.........这里部分代码省略.........
示例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;
}