【发布时间】:2011-05-11 16:42:54
【问题描述】:
我有一个使用性能计数器的应用程序,它已经工作了几个月。现在,在我的开发机器和另一台开发机器上,当我调用 PerformanceCounterCategory.Exists 时它已经开始挂起。据我所知,它无限期地挂起。我使用哪个类别作为输入并不重要,其他使用 API 的应用程序表现出相同的行为。
调试(使用 MS 符号服务器)表明挂起的是对 Microsoft.Win32.RegistryKey 的调用。进一步调查表明,正是这条线挂起:
while (Win32Native.ERROR_MORE_DATA == (r = Win32Native.RegQueryValueEx(hkey, name, null, ref type, blob, ref sizeInput))) {
这基本上是一个尝试为性能计数器数据分配足够内存的循环。它从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 switch case below). We want to wait most certainly more than a 2min window.
// The curent wait time of up to 10mins takes care of the known stress deadlock issues. In most
// cases we wouldn't wait for more than 2mins anyways but in worst cases how much ever time
// we wait may not be sufficient if the Win32 code keeps running into this deadlock again
// and again. A condition very rare but possible in theory. We would get back to the user
// in this case with InvalidOperationException after the wait time expires.
以前有人见过这种行为吗?我能做些什么来解决这个问题?
【问题讨论】:
-
非常好的研究,+1。是的,继续担心,整个性能计数器 API 变得无法维护。一个过于简单的模型,无法再固定在下一个版本的 Windows 之上。 Vista从中取得了重大突破。祝你好运!
-
所有 Windows 版本都容易受到该问题的影响吗?
标签: c# .net debugging performancecounter