C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

C# Conditional debugging - Debugging a thread


Posted Date: 03 Jul 2009    Resource Type: Articles    Category: .NET Framework
Author: ABitSmartMember Level: Diamond    
Rating: 1 out of 5Points: 5



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



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Debugging using conditional breakpoints  .  Debugging using breakpoints  .  Debugging  .  Conditional Breakpoints  .  Breakpoints  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Passing variables from on form to another in a windows application
Previous Resource: DotNet NameSpaces
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use