如果我执行此代码
PerformanceCounterCategory cat = new PerformanceCounterCategory("Process");
var instances = cat.GetInstanceNames(); // OutOfMemoryException
我得到OutOfMemoryException
完整的堆栈跟踪
A first chance exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll
System.OutOfMemoryException: An Exception of Type "System.OutOfMemoryException" occured.
at Microsoft.Win32.RegistryKey.InternalGetValue(String name, Object defaultValue, Boolean doNotExpand, Boolean checkSecurity)
at Microsoft.Win32.RegistryKey.GetValue(String name)
at System.Diagnostics.PerformanceMonitor.GetData(String item)
at System.Diagnostics.PerformanceCounterLib.GetPerformanceData(String item)
at System.Diagnostics.PerformanceCounterLib.get_CategoryTable()
at System.Diagnostics.PerformanceCounterLib.GetCategorySample(String machine, String category)
at System.Diagnostics.PerformanceCounterCategory.GetCounterInstances(String categoryName, String machineName)
at WindowsFormsApplication5.Form1.button1_Click(Object sender, EventArgs e)
这只发生在x64 exe中,如果我在x86下运行相同的代码它可以工作。任何想法如何解决这个问题?
操作系统是Windows 8.1 x64,内存为8GB(这不是物理内存问题)。
答案 0 :(得分:1)
我最终通过知识库文章How to manually rebuild Performance Counter Library values
解决了这个问题Perfc009.dat
Perfh009.dat
和%Systemroot%\System32
sources\install.wim
(Windows 8 Pro文件夹2\Windows\System32\
)中提取文件。First Counter, First Help, Last Counter, Last Help
lodctr /R
(我在System32和Syswow64文件夹中从管理员cmd提示执行此操作以确保)重新启用第三方计数器InstallUtil /i Microsoft.Mom.ConfigService.dll
但在我的情况下这不是必需的。