One of the cool feature of VS is the ability to set conditional breakpoints i.e. setting a breakpoint which hits based on a condition. When the condition is True the breakpoint will hit or else it won't.
These are the steps to add a conditional breakpoint,
Steps to set a conditional breakpoint: 1. Add a normal breakpoint (known as unconditional breakpoint) 2. Right-click n the breakpoint icon 3. From the menu select "Condition...". This will invoke a dialog box 4. In the dialog box you have an textbox to input your expression e.g., myVariable, myVariable == "test", etc. 5. The dialog box has two options a. Is true When you want the breakpoint to hit whenever there the expression specified in evaluates to true. b. Has changed When you want the breakpoint to hit whenever there is change in value of expression specified. 6. Hit ok
One of the ways this feature comes handy is while debugging a thread. We know that setting a breakpoint in a thread scenario is painful as the the different thread execution moves the current cursor location randomly based on the executing thread. So it is impossible to debug a single thread. Well, it is possible.
We just have to set a conditional breakpoint based on the thread id or name. Once you know which thread you want to debug then you just add a conditional breakpoint at the place you want to debug for this thread. Adding the expression as,
Thread.CurrentThread.ManagedThreadId == TheThreadIdYouWantToDebug
Or
Thread.CurrentThread.Name == "NameOfThreadYouWantToDebug";
Whenever the expression evaluates to True the breakpoint will hit and it will mean the thread you want to debug is the current thread for the breakpoint.
Have fun.
For more details, visit http://abitsmart.com/?p=131
|
No responses found. Be the first to respond and make money from revenue sharing program.
|