Groups | Blog | Home
all groups > visual studio .net debugging > july 2006 >

visual studio .net debugging : Breaking on conditions


Abstract Dissonance
7/15/2006 3:11:29 AM
Is there an easy way to break to code while debugging an app in VS.net other
then setting breakpoints? I'd like to break on when a file menu is clicked
on selection but I can't find a way to do this using the vs.net debugger.
(I know there might be a long convoluted way to do this but surely there is
an easy way too?)

Thanks,
Jon


Dave Sexton
7/22/2006 12:45:29 PM
Hi Jon,

You won't be able to break on code that isn't yours, such as internal
framework code.

If you've declared an event handler for the Select event (or Click event if
you're using a 2.0 MenuStrip) you can just set a break point.

If you want to break only in the event that some flag is set or after
verifying the state of your program then you can set a Condition on your
breakpoint. If the state flag is more complex than you would like to code
in a Condition then you can use the following code in your application code
to launch and attach a debugger at runtime:

#if DEBUG
if (SomeComplexConditionIsTrue())
{
// launch debugger (this code should run whether or not we are
already attached
// although it isn't necessary if you plan to execute your program
with F5 in VS.NET).
System.Diagnostics.Debugger.Launch();

// break into the debugger
System.Diagnostics.Debugger.Break();
}
#endif

- Dave Sexton

[quoted text, click to view]

AddThis Social Bookmark Button