views:

48

answers:

3

I have an application with 4 threads working the same code. However, when I step it jumps between the different threads. How can I lock it to one thread so the other threads are ignored for debugging?

+5  A: 

Yes.

In the Threads window (Debug -> Windows -> Threads) right-click the thread you want and select "switch to thread".

You can also choose "freeze" on the threads you don't want to debug in order to keep them from running. Don't forget to "thaw" them if you expect them to do work, however.

Further reading.

jeffamaphone
+1  A: 

You could also put a conditional breakpoint in your code and put the thread.Id == [someValue] or Thread.Name == "[SOmename]" in the breakpoint condition...

Charles Bretana
Thanks Charles, that was helpful (did not know you could do that). However, the most efficient way for me to debug is the one that jeffamaphone wrote as I do not know the name before it hits the breakpoint and sees some values
Oskar Kjellin
+1  A: 

This strongly resembles a very similar problem in VS2008 SP1. It was fixed with a post-SP hotfix. But there's other evidence that the hotfix didn't get incorporated into the code base, this feedback item was also a problem. It isn't that unusual for hotfixes to not get integrated back.

There isn't a feedback item that exactly describes your problem, at least that I can find. I'd recommend you file one. Given the usual trouble with getting a repro for bugs like this, I'd strongly recommend you include a repro project that exhibits this problem with instructions on how to reproduce the issue.

There is a workaround of sorts for your issue, you could go into Debug + Windows + Threads, right-click the threads you don't want to debug and select Freeze. Don't forget to Thaw them later.

Hans Passant