开发者

VS2008 Suspending all threads upon hitting breakpoint

I must be missing something.. (I'm used to using eclipse)

Visual Studio 2008 appears to suspend all threads when I hit a breakpoin开发者_运维百科t - is this normal? If so, is there an option that will only suspend the thread on which the breakpoint has hit?


Yes this is completely normal for a debugger to do. Consider what would happen if it did not. Any value the debugger displayed would have to be considered out of date the moment it was displayed because any of the other running threads could be changing the value out from under it.

I don't believe there is a way to break in Visual Studio without pausing all threads.


As Jared has said, this is normal behavior in VS. There are, however, some things that you can do to tweak the behavior like creating breakpoint conditions. I found an article that mentions setting a breakpoint condition to look for a specific thread:

Tip: Break only when a specific thread calls a method: To set a per-thread breakpoint, you need to uniquely identify a particular thread that you have given a name with its Name property. You can set a conditional breakpoint for a thread by creating a conditional expression such as "ThreadToStopOn" == Thread.CurrentThread.Name .

You can manually change the name of a thread in the Watch window by watching variable "myThread" and entering a Name value for it in the value window. If you don't have a current thread variable to work with, you can use Thread.CurrentThread.Name to set the current thread's name. There is also a private integer variable in the Thread class, DONT_USE_InternalThread, this is unique to each thread. You can use the Threads window to get to the thread you want to stop on, and in the Watch window, enter Thread.CurrentThread.DONT_USE_InternalThread to see the value of it so you can create the right conditional breakpoint expression.

Here are a few more articles that cover breakpont conditions:

http://www.professionalvisualstudio.com/blog/2009/04/30/debugging-threads-in-visual-studio-with-breakpoint-conditions-and-actions/

http://www.blackwasp.co.uk/VSBreakpoints.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜