Visual Studio Tip: Show Threads in Source

May 29, 2012

Debugging multithreaded applications is always hard, so any help we can get from the debugger is appreciated.

Here’s one tip that can help using Visual Studio 2010 when many threads are running at the same time, some of which run similar code.It’s tedious to lookup each thread’s call stack to see where its next instruction pointer is located. Here’s the Threads window in action:

image

To find the actual source line each thread is at the breakpoint moment, we’ll need to switch to that thread by double clicking it in the Threads window and then we’ll see something like this in the editor:

image

We can keep double clicking threads and get to each one’s source.

The Debug toolbar has a nice alternative, called “Show Threads in Source”:

image

Clicking the marked button causes Visual Studio to show locations of other threads with a special icon:

image

This means there is at least one thread is at the location marked with the “wavy” icon. Hovering that icon displays a tooltip for those threads that are, in fact, at that source line:

image

With this, you can get a quick sense of where threads are running at the moment.

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*