【发布时间】:2015-02-16 04:15:30
【问题描述】:
我有 2 段代码偶尔会抛出错误。如果我在 server.FullyQualifiedDomainName 中定义的服务器上本地运行应用程序,我不会收到任何错误,永远不会。如果我远程运行应用程序并通过网络读取计数器,我将得到下面定义的错误。错误不会一直发生。我在某处读过网络上的性能计数器有点不稳定...无论如何要获得更可靠的响应?
读取类别的代码:
var windowsCounterCategory = new PerformanceCounterCategory(counterCategory, server.FullyQualifiedDomainName);
var serviceGuidsStr = windowsCounterCategory.GetInstanceNames();
错误:
System.InvalidOperationException: Could not Read Category Index: 8324.
at System.Diagnostics.CategorySample..ctor(Byte[] data, CategoryEntry entry, PerformanceCounterLib library)
at System.Diagnostics.PerformanceCounterLib.GetCategorySample(String category)
at System.Diagnostics.PerformanceCounterLib.GetCategorySample(String machine, String category)
at System.Diagnostics.PerformanceCounterCategory.GetCounterInstances(String categoryName, String machineName)
at System.Diagnostics.PerformanceCounterCategory.GetInstanceNames()
读取计数器值的代码:
using (var perfomanceCounter = new PerformanceCounter(categoryName, counterName, instanceId, Service.Server.FullyQualifiedDomainName))
{
var counterValue = perfomanceCounter.RawValue;
log.Trace("Read counter value " + counterValue.ToString());
return counterValue;
}
错误:
System.InvalidOperationException: Could not Read Category Index: 8324.
at System.Diagnostics.CategorySample..ctor(Byte[] data, CategoryEntry entry, PerformanceCounterLib library)
at System.Diagnostics.PerformanceCounterLib.GetCategorySample(String category)
at System.Diagnostics.PerformanceCounterLib.GetCategorySample(String machine, String category)
at System.Diagnostics.PerformanceCounter.NextSample()
at System.Diagnostics.PerformanceCounter.get_RawValue()
【问题讨论】:
标签: c# .net performancecounter system.diagnostics