John Robbins' Blog

Neat New Multithreaded Debugging Features in VS 2008

Sometimes the little features can make a world of difference. The VS 2008 debugger adds some help to those of us dealing with many threads running in our applications. The first is Show Threads in Source, which you can turn on either by selecting it from the context menu in the Threads window or the toggle button on the Debug toolbar (it's the one with the wavy lines and plus sign). Once Show Threads in Source, you'll see some new icons in the editor margin as shown below.

If you look closely, the breakpoint sphere has the squiggly lines through it. Below the current location marker, you also see the squiggly lines. When you mouse over those items, the debugger tells you which threads are currently executing that location. The grey on the source code lines, also help you see that another thread is executing that location. In the screen shot, it's showing the three threads I've named, using Thread.CurrentThread.Name in my code. Just being able to see what threads are also executing at that location at a glance is extremely nice.

While naming your threads in your code is very useful, it's a bit problematic as a thread can only be named once or it throws an InvalidOperationException. What would be better is if you could set the thread name in the debugger so you don't have to add the naming to your code. VS 2008 now allows us to do the thread naming simply by selecting the thread in the Threads window and starting to type. You can also right click in the Thread window and select Rename. The following shows the renamed threads in the Threads window.

You also see more color in the Threads window, with the Main and Worker threads obvious at a glance. The last new multithreaded debugging feature is also shown in the screen shot above; flagging interesting threads. As .NET applications in particular have threads running all over the place, it sometimes gets hard to monitor just a few key threads. Once you flag a thread in the Threads window, the very underutilized Debug Location toolbar has a new button to show only the interesting threads. The quick Windows Forms program I tossed together to look at these new features has 12 threads running when doing managed debugging. Since I only care about five of those threads, it's super easy to monitor them now.

As an added bonus, I wanted to point out one other new feature I stumbled across and have wanted for a long time. If you right click on a folder, project, or solution in Solution Explorer, you'll see a new menu item show up:

While all the big features like JavaScript Intellisense and debugging are getting all the press, sometimes the little tweaks can certainly make your life much easier.

On Aug 1 2007 12:08 PMBy jrobbins With 12 Comments

Comments (12)

  1. Cool, thanks for this info. I've always thought the VS debugging was lacking when it came to parallel programming. It's nice to see these improvments.

  2. Nice summary of the new VS2008 thread features. We've written an parallel debugging add-in (Allinea DDTLite) for VS2008 that adds a lot of cool things for multi-threaded and multi-process debugging - easy group/individual control, variable comparisons and so on. There'a a free 30-day trial at www.allinea.com/ddtlite, so have some fun with it and let me know what you think!

Leave a Comment

Archives

Tags