我有一个使用性能计数器的应用程序,已经工作了几个月.现在,在我的开发机器和另一台开发人员机器上,当我调用PerformanceCounterCategory.Exists时它已经开始挂起.据我所知,它无限期地挂起.我使用哪个类别作为输入并不重要,使用API的其他应用程序表现出相同的行为.
调试(使用MS Symbol Servers)显示它是对挂起的Microsoft.Win32.RegistryKey的调用.进一步的调查表明,这条线是挂起的:
while (Win32Native.ERROR_MORE_DATA == (r = Win32Native.RegQueryValueEx(hkey, name, null, ref type, blob, ref sizeInput))) {
Run Code Online (Sandbox Code Playgroud)
这基本上是一个尝试为性能计数器数据分配足够内存的循环.它开始于size = 65000并进行一些迭代.在第4次通话中size = 520000,Win32Native.RegQueryValueEx挂起时.
此外,相当令人担忧的是,我在PerformanceCounterLib.GetData的参考源中找到了这条评论:
// Win32 RegQueryValueEx for perf data could deadlock (for a Mutex) up to 2mins in some
// scenarios before they detect it and exit gracefully. In the mean time, ERROR_BUSY,
// ERROR_NOT_READY etc can be seen by other concurrent calls (which is the reason for the
// wait loop and …Run Code Online (Sandbox Code Playgroud)