views:

347

answers:

1

The program I'm currently working on occasionally hangs with an AppHangB1 problem event. I have traced it to a specific series of actions, but it seems to be a type of heisenbug, as whenever I step through the code, it doesn't manifest itself. And once the program hangs, I can't pause the program to see where it is hung in Visual Studio. There are many things going on in this application (unmanaged interop, multi-threading, etc.), so it could be any number of things that are wrong in my particular application.

I am not looking for anyone to solve my problem for me, I'm just wondering what types of things could cause this type of hang? I found a couple hits on Google, but nothing that helped. Any debugging tricks for .NET applications that could help pinpoint the problem would also help.

+1  A: 

The AppHangB1 event is triggered when the UI thread doesn't respond to messages for several seconds and the user tries to terminate it. Hangs can be caused by just about anything: busy loops in your code, doing network or disk I/O on the UI thread, the UI thread being blocked on a lock held by a background thread doing a long running task, etc.

It's a bit concerning that Visual Studio can't break at the point of the hang. Are you attaching for managed-only debugging or for mixed-mode debugging? You could try using Windbg (http://www.microsoft.com/whdc/devtools/debugging/default.mspx) to non-invasively attach to the process and try to get a stack trace of the hung thread (you want to look at using !clrstack to get the managed stack trace). The learning curve for Windbg is pretty steep, so you might just want to collect a dump that you can debug in Visual Studio.

Michael
My debugging skills don't extend much beyond the VS2008 tools. I have used WinDbg in the past, but am not very familiar with it. I am unable to get a trace (in VS or WinDbg) on the occasion that the app does hang. Both debugging apps hang when my app hangs. Any suggestions on how to get a trace?
bsruth
Try remote debugging. If your app is doing some very strange and horking the desktop, doing a remote debug might help since it's UI couldn't be hung by your app.
Michael