删除性能计数器类别失败

时间:2012-12-16 15:00:23

标签: c# performancecounter perfmon

我有这个简单的代码:

public void CreateCounters() {
    if (PerformanceCounterCategory.Exists(_categoryName)) {
        PerformanceCounterCategory.Delete(_categoryName);
    }

    // create logic…
}

适用于我的机器。 我在我的服务器上运行它,得到以下堆栈跟踪:

System has detected a fatal error. EXITING... 
NativeErrorCode: 1010 
ErrorCode: -2147467259 
Message: The configuration registry key is invalid 
TargetSite: Void RegisterFiles(System.String, Boolean) 
HelpLink:  
Source: System 
Stack Trace: 
 at System.Diagnostics.PerformanceCounterLib.RegisterFiles(String arg0, Boolean unregister) 
 at System.Diagnostics.PerformanceCounterCategory.Delete(String categoryName) 
 at myApp.Common.Utils.PerformanceCounters.PerformanceCounters.CreateCounters() 
 at myApp.Common.Utils.PerformanceCounters.myAppPerformanceCounterReporter.Init() 
 at myApp.Common.Utils.PerformanceCounters.myAppPerformanceCounterReporter.get_Instance() 
 at myApp.Program.Main(String[] args) 

服务器上存在该类别,我可以在perfmon GUI中看到它。

1 个答案:

答案 0 :(得分:5)

确定这是性能计数器机制中的一些错误,应该通过以下脚本修复:

cd %systemroot%\system32
lodctr /R

点击此链接:http://geekswithblogs.net/robz/archive/2008/08/10/possible-performance-counter-corruption-or-performance-counters-are-just-disabled.aspx