views:

291

answers:

3

When debugging multi threaded .NET apps in VS (2008) I frequently want to step through code. When I press F10 quite often I find VS jumping to a statement in another thread. Its really confusing and always throws me off.

I can work around it by chucking in a million breakpoints.

Is there a cleaner way of asking VS debugger to go to the next statement in the current thread?

+3  A: 

Probably a much simpler way would be to Freeze any thread that you're not interested in tracing (right click in the Threads window). This may mean a little manual manipulation for you, and won't accurately represent thread interaction, but you won't jump from one thread to the next.

Alan McBee
This works, but has its limitations, in particular it falls apart when your next step depends on other threads doing stuff ...
Sam Saffron
A: 

Agree with @Alan McBee. I think in VS 2010 they're adding a 'freeze all threads except this one' command, which will make this easier, too. But I think there's no other way to achieve your goal (e.g. must either freeze threads or set breakpoints).

Brian
+1  A: 

John Robbins, an authority on Windows debugging, just posted a macro that allows you to freeze and thaw threads in bulk in VS 2008.

This certainly makes things much easier. Thread inter-dependencies may end up causing issues, nonetheless this is a workable solution most of the time.

Sam Saffron