• 10 hours
  • Medium

Free online content available in this course.

course.header.alt.is_video

course.header.alt.is_certifying

Got it!

Last updated on 8/6/19

Control the execution of the code

Let me remind you that we’re in the model’s CreateTask method, which is called with the value “sleep” in the T_TodoModels.cs VerifyAddTasks test.

Once it's stopped on an instruction, there are two possible choices:

  • Move down the method code called via Step Into (F11) by suspending the execution.

  • Let the debugger execute it, including the calls to sub-functions, using Step Over 

    (F10), and pause once the execution is finished.

Both actions can be accessed from the Visual Studio Debug toolbar:

Going down to a method or just executing it
Going down to a method or just executing it

You can access them directly using the keyboard shortcuts F11 and F10.

It’s also possible to let the code execute up to a particular instruction. To do this, leave the mouse stationary for a few seconds to make a green symbol appear:

Leaving to execute up to an instruction
Leaving to execute up to an instruction

Clicking on this does exactly what we want: it executes the code and suspends execution just before the return.

And what if we want to skip executing InternalAddTask?

Again, leave the mouse in front of the return for a few seconds, and press the Ctrl key to see a symbol appear. It will be yellow this time:

Skipping executing instructions
Skipping executing instructions

Right-clicking also gives you access to the two functions Run to Cursor (Ctrl  +  F10) and Set Next Statement (Ctrl  +  Shift  +  F10):

Actions available on right click
Actions available on right-click

Let's recap!

You now have all the means for navigating step-by-step through the execution of the code to:

  • Go down to a method.

  • Execute a method.

  • Execute everything up to an instruction.

  • Completely skip execution of one part of the code.

With these tools at your disposal, you are now able to find the origin of the bug and fix it. This will be the subject of the final chapter in this part of the course on debugging C# applications. 😉

Example of certificate of achievement
Example of certificate of achievement