C# windows server 2012 R2上未设置性能计数器值
创建在windows 7开发计算机上工作的新性能计数器后,原始值的设置在部署到windows server 2012 R2时将不起作用 自定义类别中的现有计数器仍能正常工作,但不会设置新计数器 我已尝试删除整个类别并重新创建所有计数器,但它仍然有未设置新计数器的相同结果C# windows server 2012 R2上未设置性能计数器值,c#,performance-monitor,C#,Performance Monitor,创建在windows 7开发计算机上工作的新性能计数器后,原始值的设置在部署到windows server 2012 R2时将不起作用 自定义类别中的现有计数器仍能正常工作,但不会设置新计数器 我已尝试删除整个类别并重新创建所有计数器,但它仍然有未设置新计数器的相同结果 const string counterCategoryName = "Statistics"; var requiredCounters = GetAllCounters(); // Check counters exis
const string counterCategoryName = "Statistics";
var requiredCounters = GetAllCounters();
// Check counters exist
PerformanceCounterCategory category = null;
if (PerformanceCounterCategory.Exists(counterCategoryName) == false // Category exists
|| !requiredCounters.All(counter =>
PerformanceCounterCategory.GetCategories()
.Single(z => z.CategoryName == counterCategoryName)
.CounterExists(counter.Name))) // All counters exist
{
if (PerformanceCounterCategory.Exists(counterCategoryName))
{
// This occurs in case there is a counter missing, we should delete the existing category and rebuild it with all the new counters
PerformanceCounterCategory.Delete(counterCategoryName);
}
var counterDatas = new CounterCreationDataCollection();
foreach (var counter in requiredCounters.Select(counterDesc => new CounterCreationData
{
CounterName = counterDesc.Name,
CounterHelp = counterDesc.Description,
CounterType = PerformanceCounterType.NumberOfItems64 //counterDesc.Type
}))
{
counterDatas.Add(counter);
}
category = PerformanceCounterCategory.Create(counterCategoryName, "Statistics",PerformanceCounterCategoryType.SingleInstance, counterDatas);
}
else
{
category = PerformanceCounterCategory.GetCategories()
.Single(z => z.CategoryName == counterCategoryName);
}
在测试这个问题时,我发现添加到类别中的新计数器实际上正在写入相同的内存空间,这是最初添加的最后一个计数器。作为这个问题的解决办法,我创建了一个全新的类别(即不同的名称),计数器都能正常工作。唯一的问题是,如果我希望在此之后添加新计数器,我需要再次执行相同的操作。在测试此问题时,我发现已添加到类别的新计数器实际上正在写入相同的内存空间,这是最初添加的最后一个计数器。作为这个问题的解决办法,我创建了一个全新的类别(即不同的名称),计数器都能正常工作。唯一的问题是,如果我希望在此之后添加一个新计数器,我将需要再次执行相同的操作。