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?

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
CJ7
  • 22,579
  • 65
  • 193
  • 321
  • Does your application have long running routines when it is busy and unable to respond to Windows messages? – jac Apr 06 '12 at 02:51
  • Not that I am aware of. This event log comes from a client site. I would like the event to show more information about what was happening at the time. – CJ7 Apr 06 '12 at 07:05
  • You could do a process memory dump (or let the user do it) when the application hangs and then analyze it and look at the call stack. – MicSim Apr 19 '12 at 11:45
  • Do you know if the CPU was using 100% or the committed memory consumption of the process close to the time frame when it hung? – Warren Rox Apr 25 '12 at 03:21

4 Answers4

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.

Rick Brewster
  • 3,374
  • 1
  • 17
  • 21
  • The link above is dead, try this one https://www.microsoft.com/en-US/download/details.aspx?id=39982 it shows me only ADK for Win 8.1... – Jakob Jan 26 '16 at 09:07
  • I think it's part of the SDK now, starting with Windows 10. https://dev.windows.com/en-us/downloads/windows-10-sdk – Rick Brewster Jan 26 '16 at 19:43
  • The latest download link can be found on this page: https://learn.microsoft.com/en-us/windows-hardware/get-started/adk-install?ocid=tia-235208000 – Hakan Yildizhan Mar 19 '21 at 23:48
2

The Application Hang event means that Windows has decided that the application is unresponsive. Since the event is generated by the operating system and not the application, your options for getting additional information in the event are extremely limited.

This is what seems to be available on an Application Hang event:

Message: Hanging application %1, version %2, hang module %3, version %4, hang address 0x%5.

From:

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

If you believe the cause of the event is something that your application does (as opposed to something in the environment where the application is running), then instead of trying to pass info to the hang event, you should raise the level of log info to debug mode and look in your application's log file to see what it is doing just prior to becoming unresponsive.

If you lack logging information, or a logging framework in your application, then that is where you should be focusing your efforts. The upside is that you will benefit from better logging in the future as well. Use a logging framework however, so you can disable debug level logging in a production environment, when everything is running smoothly.

SPE
  • 311
  • 1
  • 7
2

I would approach this by reviewing the code in the module that Windows has determined has hung, the name of which was written to the event log. Attempting to get more detail in the hang event will not be possible because when Windows has determined the app is unresponsive, it is too late.

Into the module that is hanging I would add multiple calls to DoEvents as well as logging status messages directly into the EventLog. Adding a logging framework at this point would introduce complexity and involve either a database or file access in which to store the logs.

Windows thinks the app has hung because it has stopped responding to messages. Unfortunately, implementing a second thread in your VB6 app is not trivial, unlike .NET. Never-the-less, adding another thread would keep the app responsive, but then you would likely still be left with answering the question, "why is the code taking so long to execute?"

Brian Leeming
  • 11,540
  • 8
  • 32
  • 52
0

Getting information from windows event perspective will not help. Try to have tracing in your application which helps you to get the exact cause.

mannu2050
  • 403
  • 3
  • 11