3

One of our legacy products is a Winforms application and instead of using background threads it does everything on the main UI thread. It has a constant loop running on this main thread that calls Application.DoEvents() every 20 ms. Once in a while the application just hangs at the DoEvents call. My question is how do I find out in what queued event call the code is hanging?

P.S. Does someone know of a tool that I can use to get the stack trace of every thread in a process?

Also, this is only happening at a production client and we got to get a fix out now. No possibility in installing VS at the client either.

John K
  • 830
  • 1
  • 7
  • 18
  • 7
    That code needs to *seriously* be refactored. – Tejs May 11 '11 at 18:59
  • Does it hang during debugging? –  May 11 '11 at 19:00
  • 1
    Tool is called Visual Studio. You pause process, and go to Threads window. – Andrey May 11 '11 at 19:03
  • If everything is done on the UI thread you only need to get the stack trace of the UI thread. – Albin Sunnanbo May 11 '11 at 19:06
  • I second @Tejs, the time for analyzing the problem is better spend in refactoring your form. Basically you have to move the loop to a background worker thread and change any call from the background thread into the UI thread so that it is using the BeginInvoke-pattern. – Dirk Vollmar May 11 '11 at 19:06
  • Looks like we are going to refactor the code... when I posted I didn't think it was an option because my dev said it would be significant work but when looked at closer it isn't that bad at least just for that one form. – John K May 12 '11 at 00:54
  • BTW Tejs, although you didn't really answer my question the solution to the hang issue is to refactor. Post as answer and I will accept. – John K May 12 '11 at 01:03

2 Answers2

2

You can do that in visual studio, just attach to the process, break execution and open the threads windows.

Menu: Debug->Windows->Threads

Albin Sunnanbo
  • 46,430
  • 8
  • 69
  • 108
  • Unfortunately that will not work. The issue is being experienced at a customer and we can't reproduce it in-house or install VS on their machine. I will edit the original question. – John K May 11 '11 at 21:29
0

I found the tool I was looking for. WinDbg

It can get the stack traces for a currently running windows process. However it does require the PDB files for that application.

John K
  • 830
  • 1
  • 7
  • 18