C# 如何修复PerformanceCounterCategory.GetInstanceName的OutOfMemoryException
如果我执行这个代码C# 如何修复PerformanceCounterCategory.GetInstanceName的OutOfMemoryException,c#,.net,performancecounter,C#,.net,Performancecounter,如果我执行这个代码 PerformanceCounterCategory cat = new PerformanceCounterCategory("Process"); var instances = cat.GetInstanceNames(); // OutOfMemoryException 我得到一个OutOfMemoryException完整堆栈跟踪是 A first chance exception of type 'System.OutOfMemoryException' occ
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)
只有在x86下运行相同的代码时,才会在x64 exe中发生这种情况。有什么办法解决这个问题吗
操作系统是Windows 8.1 x64,带有8GB内存(这不是物理内存问题)。我最终通过一篇知识库文章解决了这个问题
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文件夹中的admin cmd提示符下做了一次,只是为了确保)重新启用第三方计数器InstallUtil/i Microsoft.Mom.ConfigService.dll
,但在我的情况下,这不是必需的哪个windows版本?在问题调用之前,您有多少可用内存?@tolanj我添加了一些详细信息“操作系统是windows 8.1 x64,具有8GB RAM(这不是物理内存问题)。=>是的,但“真正”的问题可能在代码的其他地方,即您调用cat.GetInstanceNames()时内存不足;但我想确认一下,在打那个电话之前,你有足够的空间,问题不在于其他地方的内存使用异常。因此,您可以在调用之前明确确认可用内存。另外,HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009注册表项和C:\Windows\System32\perfc009.dat文件(如果其较大,则为文本文件,仅发布sze)的内容对您有好处。通常,您只需运行
lodctr/R
命令(不执行任何其他步骤)就可以逃脱。嗯,我不买。您是否忘记列出步骤6a。重新启动机器?@500 InternalServerError-在我的情况下不是这样,我还尝试了lodctr/q
和loadctr/d:
一些第三方性能计数器@HansPassant-Noop,这对我来说是有效的,没有重新启动,甚至没有重新启动任何与性能计数器相关的服务。