8

If a VB6 app is causing an Application Hang event to appear in the Event Viewer, how can I find out more about why the application is hanging?

Does an Application Hang event mean that the app has frozen and crashed, or just that it temporarily hangs?

All I get in the event log for this event is:

Hanging application [MyAppName].exe, version [MyAppVersionNo], hang module hungapp, version 0.0.0.0, hang address 0x00000000.

That is not enough and I want to be able to find out more about why it is hanging. What code changes or other steps need to be taken to cause the app to provide more details in the event log?

4

4 回答 4

5

I recommend using the Windows Performance Toolkit. The best version to use is in the Windows Assessment & Deployment Kit, http://www.microsoft.com/download/en/details.aspx?id=28997

Once it's installed, what you do is start up Windows Performance Recorder (WPR) and click the Start button to begin recording. Next, reproduce the problem with your app. Then go back to WPR and press the Save button. Next, load up Windows Performance Analyzer and open that *.ETL file that was generated. Then you want to go to System Activity section in the Graph Explorer, expand it, and find the UI Delays graph (or it might be the first graph parked on System Activity). Double click on it to get the detailed version in an Analysis tab.

Once you find the UI delay you're interested in, you can add another graph such as CPU Usage (Sampled) from the Processing node in Graph Explorer. When the two graphs are in the same Analysis tab, their scrolling and selection will be synchronized. So you can click on the UI delay event and it will also highlight the corresponding range in CPU Usage.

于 2012-04-25T23:38:21.647 回答
2

应用程序挂起事件意味着 Windows 已确定应用程序没有响应。由于事件是由操作系统而不是应用程序生成的,因此您在事件中获取附加信息的选项非常有限。

这似乎在应用程序挂起事件中可用:

消息:挂起应用程序 %1,版本 %2,挂起模块 %3,版本 %4,挂起地址 0x%5。

从:

http://www.microsoft.com/technet/support/ee/transform.aspx?ProdName=Windows+Operating+System&ProdVer=5.2&EvtID=1002&EvtSrc=Application+Hang&LCID=1033

如果您认为事件的原因是您的应用程序所做的事情(而不是应用程序运行的环境中的事情),那么您应该将日志信息级别提高到调试模式并查看应用程序的日志文件以查看它在变得无响应之前正在做什么。

如果您的应用程序中缺少日志信息或日志框架,那么就是您应该集中精力的地方。好处是您将来也会从更好的日志记录中受益。但是,请使用日志记录框架,这样您就可以在生产环境中禁用调试级别的日志记录,当一切都运行顺利时。

于 2012-04-19T14:19:18.410 回答
2

我将通过查看 Windows 已确定已挂起的模块中的代码来解决此问题,该模块的名称已写入事件日志。尝试在挂起事件中获取更多详细信息是不可能的,因为当 Windows 确定应用程序无响应时,为时已晚。

在挂起的模块中,我将添加对 DoEvents 的多个调用,并将状态消息直接记录到 EventLog 中。此时添加日志框架会引入复杂性,并涉及存储日志的数据库或文件访问。

Windows 认为应用程序已挂起,因为它已停止响应消息。不幸的是,与 .NET 不同,在您的 VB6 应用程序中实现第二个线程并非易事。尽管如此,添加另一个线程会使应用程序保持响应,但是您可能仍然会回答这个问题,“为什么代码需要这么长时间才能执行?”

于 2012-04-19T19:24:45.650 回答
0

从 Windows 事件角度获取信息将无济于事。尝试在您的应用程序中进行跟踪,以帮助您找到确切的原因。

于 2012-04-26T11:39:15.690 回答