2

Visual Studio 2010

To stop the debugger where it currently is, I normally use Break All from Debug menu.

However, now I'm multithreading, and this does show me a place in code, and it says this is where thread A is going to execute when task is back to it.

However, right now another thread is frozen somewhere, and I'd like to access the one which is currently running. How can I do that? To know the active thread and the last line of my code it did?

Cher
  • 2,789
  • 10
  • 37
  • 64

3 Answers3

3

Have you tried DEBUG > WINDOW > THREAD ?

It will show you your currently executed thread (where your task is actually waiting) as well as other worker threads running. You can double-click on the thread you want to access its callstack and then see why it is blocked.

DevBackFlo
  • 94
  • 8
  • 2
    There you go.... I've already got the sportsmanship badge, you look like you deserve a few points and you beat me by 11 seconds. – Jeremy Thompson May 24 '16 at 13:44
  • thanks to both for the answer! Maybe then I'm understanding something wrong, but it shows me that the thread executing is A, and when I go there there is a green line which says: "This is the next statement to execute when this thread returns from the current function." So then maybe I wrongly understood my problem. I would need to find why it's stopped? – Cher May 24 '16 at 13:50
  • @JeremyThompson: haha thanks :) Indeed, I'll just need the 50 points to be able to comment in the future! – DevBackFlo May 24 '16 at 13:59
  • @CherrysaHerrim: Thread debugging is always the worst. That is what I am currently doing so I share your pain. You are right, you should try to locate where you are giving the control to another thread, this way you will know how to find a solution. Is it a GUI problem? Are you awaiting a task to finish ? And btw, once you see all the threads displayed (in the THREADS window you opened), you are first located in your awaiting thread... But this one is not much interesting for you. What else do you have in the list of other working threads ? Anything processing ? – DevBackFlo May 24 '16 at 14:02
  • thanks for your answer!! actually right now I have reason to believe I'm in unmannaged code... I'm looking in that direction to see if it gives results. – Cher May 24 '16 at 14:04
  • 1
    @CherrysaHerrim when you see the green highlighted line just put a breakpoint one line below it, press F5 and the code will halt on your breakpoint when it comes back to that thread (or that call in the stack). When the code control (yellow highlight) does come back to the thread you're interested in debugging, click the button *Freeze all threads except one I'm working on* - the button is available in the plugin I mention in my answer. Cheers – Jeremy Thompson May 24 '16 at 14:11
  • @Flo now you can comment checkout the Magic Link comment shortcuts: http://meta.stackexchange.com/a/94000/156316 – Jeremy Thompson May 24 '16 at 14:13
2

You just use the Threads window. Debug > Windows > Threads. Then you just click on the thread your interested in.

I use a Visual Studio plugin to freeze all other threads so when I step through the code it doesn't jump between the threads.

Debug Single Thread

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • Cheers it certainly is an excellent plugin! Check out its source code, great example for anyone looking at writing their own debugger extensions *unfortunately [just not this one](http://stackoverflow.com/questions/7816556/visual-studio-extend-ide-the-exception-assistant)* – Jeremy Thompson May 24 '16 at 13:47
0

Ctrl+S, D opens the Parallel Stacks window in VS 2010

Other Versions have similar functionality: See MSDN
Further reading: Walkthrough: Debugging a Parallel Application

Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62