views:

148

answers:

7

Here is the scenario: I put a break point at the beginning of a method that I want to debug... at first lets say there is Part1 in this method that I want to step into/over some of the codes... good... after that there is a While loop that I am NOT interested to step into/over it, I just want to tell the debugger that Hey you yourself run this loop for 10 times and just let me move to Part2 of my code which starts after this While loop , is it possible to do this with debugging options?

so something like this :

BreakPoint : MyMethod
{
Part One of the code : Ok, lets debug it

While Loop : I do not care, Do not want to debug it

Part Two of the code: Yes, I want to debug it too 
}
+11  A: 

Right-click on the line of code you want to run to, and click "Run To Cursor", or you can set a second breakpoint after the loop and just run.

Edit: You kind of asked two questions here. The method above will let you step over the whole loop, regardless of how many iterations it goes through. If you want to only go through the loop body 10 times, add a breakpoint on the last statement of the loop, right-click that line, click "Breakpoint", then "Hit count", then "break when hit count is equal to" and put 10 in the box that appears. This will pause the program after the loop executes 10 times (you will manually have to reposition the current statement), but will NOT break if the loop executes less than 10 times (add an additional breakpoint after the loop as I suggested above).

Jon Seigel
sorry for confusion, by 10 times I just meant lets say the loop is running 10 times and I do not want to hit the step into/over,etc ... button at least 10 times to just pass this loop.
BDotA
+2  A: 

Just put a breakpoint on Part Two. After you finish debugging part 1, hit run/f-5, and VS will run to the next breakpoint.

JMarsch
+3  A: 

You can put breakpoints before and after the while loop.

At the point before, press F5 to "continue" on to the next breakpoint.

mmsmatt
+2  A: 

Add a break point after the loop and let it continue into that break point.

Andrew Hubbs
+1  A: 

No I don't believe you can do what you are describing, your only options are those described by the other posters, it would be cool though :(

Yoda
+2  A: 

Not exactly (as in, execute a loop 10 times), but you might be able to get something very close to your desired behavior. Look into these MSDN links:

http://msdn.microsoft.com/en-us/library/system.diagnostics.debuggerstepthroughattribute.aspx http://msdn.microsoft.com/en-us/library/system.diagnostics.debuggerstepperboundaryattribute.aspx http://msdn.microsoft.com/en-us/library/system.diagnostics.debuggerstepthroughattribute.aspx

Hope that helps!

code4life
good things to know, thanks Sir.
BDotA
+1  A: 

C# Preprocessor Directives

BreakPoint : MyMethod
{
Part One of the code : Ok, lets debug it

#if !DEBUG
While Loop : I do not care, Do not want to debug it
#endif

Part Two of the code: Yes, I want to debug it too 
}
Charles Gargent
That simply omits the code at debugging time, I do not think that's what the OP wants.
Dykam