.NET 4.0 & 上的 PerformanceCountersWindows 7的 [英] PerformanceCounters on .NET 4.0 & Windows 7

查看:17
本文介绍了.NET 4.0 & 上的 PerformanceCountersWindows 7的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 VS2008 和 Vista 上运行良好的程序,但我正在 Windows 7 和 VS2010/.NET Framework 4.0 上尝试它,但它不起作用.最终的问题是 System.Diagnostics.PerformanceCounterCategory.GetCategories()(和其他 PerformanceCounterCategory 方法)不起作用.我收到 System.InvalidOperationException 消息无法加载计数器名称数据,因为从注册表中读取了无效索引 ''."

I have a program that works fine on VS2008 and Vista, but I'm trying it on Windows 7 and VS2010 / .NET Framework 4.0 and it's not working. Ultimately the problem is that System.Diagnostics.PerformanceCounterCategory.GetCategories() (and other PerformanceCounterCategory methods) is not working. I'm getting a System.InvalidOperationException with the message "Cannot load Counter Name data because an invalid index '' was read from the registry."

我可以用下面显示的非常简单的程序重现这个:

I can reproduce this with the very simple program shown below:

class Program
{
    static void Main(string[] args)
    {
        foreach (var pc in System.Diagnostics.PerformanceCounterCategory.GetCategories())
        {
            Console.WriteLine(pc.CategoryName);
        }
    }
}

我确实确保我以管理员身份运行该程序.我是否在附加 VS/Debugger 的情况下运行它并不重要.我没有另一台装有 Windows 7 或 VS2010 的机器来测试它,所以我不确定这里的哪个(或两者都有?)是复杂的.它是 Windows 7 x64,我尝试强制应用程序在 x32 和 x64 中运行,但得到相同的结果.

I did make sure I'm running the program as an admin. It doesn't matter if I run it with VS/Debugger attached or not. I don't have another machine with Windows 7 or VS2010 to test it on, so I'm not sure which is complicating things here (or both?). It is Windows 7 x64 and I've tried forcing the app to run in both x32 and x64 but get the same results.

推荐答案

我的系统上的性能计数器似乎已损坏.虽然我没有完全关注 这篇文章,它让我找到了解决方案.这是我所做的:

It seems performance counters were corrupted on my system. Although I didn't follow this post exactly, it led me to the solution. Here is what I did:

在具有管理员/提升权限的命令提示符中键入以下内容:

In an command prompt with administrator/elevate privileges typed the following:

lodctr /?

里面有用的东西...

然后输入:

lodctr /R

根据上一步的文档,这让 Windows 根据当前的注册表设置和备份 INI 文件从头开始重建 perf 注册表字符串和信息.我有一种感觉魔法.但是,接下来我注意到 .NET 性能计数器不再存在,因此基于 this 我输入以下内容来重新加载它们:

According to the docs from the prior step, this gets windows to rebuild the perf registry strings and info from scratch based on the current registry settings and backup INI files. I have a feeling this is what did the magic. However, next I noticed the .NET performance counters were not there anymore so based on this I typed the following to reload them:

lodctr "C:WindowsMicrosoft.NETFramework64v4.0.20506corperfmonsymbols.ini"

请注意,此路径适用于 x64 上的 .NET Framework 4.0.您可以想象框架/平台的其他变体的路径.我猜测你应该总是从你安装的 .NET 框架的最高版本加载计数器,但这只是一个猜测.

Note that this path is for .NET Framework 4.0 on x64. You can imagine the path for other variations of the framework/platform. I'm guessing you should always load the counters from the highest version of the .NET framework that you have installed, but that is just a guess.

我希望有一天这能帮助其他人!

I hope this helps someone else someday!

这篇关于.NET 4.0 & 上的 PerformanceCountersWindows 7的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆