Debug code with force run to cursor

Harshada Hole

Have you ever had an experience when breakpoints in your application cause some disruption in your debugging, because you may need to test your updated code or focus on another area that does not need those break conditions? For these scenarios, you are forced to either remove or disable the breakpoints or keep pressing continue until you hit the desired line of code.

Starting with Visual Studio 2022 Preview 2, you can use “Force Run To Cursor”, for these scenarios. It is like “Run To Cursor,” but you can keep your breakpoints and the debugger will skip over them until it reaches the line of code with the cursor. It will also skip any of the first-chance exceptions break conditions that may occur.

Debug your application faster while skipping all the breakpoints

To run directly to your cursor location, in source code or the Call Stack window, select the line you want to break at, right-click and select “Force Run to Cursor”.

Force run to Cursor

The application will attach the Visual Studio debugger and pause at the cursor location, any breakpoints and first-chance exceptions encountered during execution are temporarily disabled. We can evaluate the program’s state at that point. Once Force Run To Cursor is executed, the breakpoints and exceptions go back to their original state.

Here is a simple example, “Force Run To Cursor” will continue the execution and break at line 8 where we executed the Force run. The breakpoints inside the createMessage() and SendMessage methods will be skipped.

Code Sample

Point and click force run to cursor

When in an active debug session, a green glyph with the tooltip “Force run execution to here” appears next to the line of code where your mouse hovers along with withholding of a Shift key.


Force run execution glyph

Continuing the same example as above, here we are executing the “Force run to Cursor” using the green glyph button.

Text Description automatically generated


Special notes

To pause at the “Force Run To Cursor”, your line of code needs to be reachable. In other words, the line should belong to the condition/function/action that gets called when the application is running.

The program can also stop sooner if an unhandled exception occurs before reaching that line.

You can also get out of the “Force Run To Cursor” mode when you either:

  • Stop debugging
  • Hit an exception after reenabling
  • Select Break all (I.e., select pause button on the toolbar)
  • Hit a new breakpoint
  • Hit an existing breakpoint after reenabling it


Wrap up

“Force Run To Cursor” provides a convenient way of debugging your application when you want to skip your breakpoints. Try it out by downloading Visual Studio Preview 2 now. Please drop your questions and comments in the section below or share your feedback at Developer Community or tweet @VS_Debugger.




Discussion is closed. Login to edit/delete existing comments.

  • Daniel Smith 0

    This is great, I love little productivity enhancements like this!

  • Ed DoreMicrosoft employee 0

    As much exploratory debugging and setting of BP’s that I do, this is a crazy cool feature.

  • hitesh davey 0

    Very useful feature!
    When debugging code I prefer keyboard shortcuts. What is the shortcut key to run this option?

Feedback usabilla icon