Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log a stack trace when Windows detects app hang

The Windows 7 window manager regularly detects my WPF app as being hung, ghosts it and pops up a not responding message. I've been using the app for several weeks and haven't seen it but a user with the same hardware as me says he gets it regularly.

Everything that can be is run in a task on another thread, so I'm not sure where to begin looking for the issue. If the user waits for the application to respond it recovers quickly so I'm assuming the issue is something on the GUI thread that occasionally takes just over 5 seconds to run.

Is there any way I can detect when the DWM thinks the app has hung so I can log a stack trace?

like image 435
Skrealin Avatar asked Nov 05 '22 11:11

Skrealin


1 Answers

I haven't done this in a WPF app, but the traditional way would be to send a WM_NULL message from a background thread every so often using SendMessageTimeout, and if the main UI thread doesn't process the message in, say, 30 seconds, generate a stack dump for that thread.

like image 192
500 - Internal Server Error Avatar answered Nov 09 '22 13:11

500 - Internal Server Error