{"id":233252,"date":"2021-07-15T11:00:53","date_gmt":"2021-07-15T18:00:53","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/visualstudio\/?p=233252"},"modified":"2021-07-15T14:50:27","modified_gmt":"2021-07-15T21:50:27","slug":"debug-with-force-run-to-cursor","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/debug-with-force-run-to-cursor\/","title":{"rendered":"Debug code with force run to cursor"},"content":{"rendered":"<p>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.<\/p>\n<p>Starting with Visual Studio 2022 Preview 2, you can use &#8220;Force Run To Cursor&#8221;, for these scenarios. It is like &#8220;Run To Cursor,&#8221; 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.<\/p>\n<h2>Debug your application faster while skipping all the breakpoints<\/h2>\n<p>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 \u201cForce Run to Cursor&#8221;.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2021\/07\/exmaple-2.png\"><img decoding=\"async\" class=\"wp-image-233263 size-medium aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2021\/07\/exmaple-2-300x215.png\" alt=\"Force run to Cursor \" width=\"300\" height=\"215\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2021\/07\/exmaple-2-300x215.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2021\/07\/exmaple-2.png 503w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>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&#8217;s state at that point. Once Force Run To Cursor is executed, the breakpoints and exceptions go back to their original state.<\/p>\n<p>Here is a simple example, &#8220;Force Run To Cursor&#8221; 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.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2021\/07\/example.png\"><img decoding=\"async\" class=\"wp-image-233264 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2021\/07\/example-300x214.png\" alt=\"Code Sample \" width=\"521\" height=\"371\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2021\/07\/example-300x214.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2021\/07\/example-1024x729.png 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2021\/07\/example-768x547.png 768w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2021\/07\/example.png 1310w\" sizes=\"(max-width: 521px) 100vw, 521px\" \/><\/a><\/p>\n<h2>Point and click force run to cursor<\/h2>\n<p>When in an active debug session, a green glyph with the tooltip \u201cForce run execution to here\u201d appears next to the line of code where your mouse hovers along with withholding of a Shift key.<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" class=\"wp-image-233256 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2021\/07\/a-screenshot-of-a-computer-description-automatica-3.png\" alt=\"Force run execution glyph \" width=\"521\" height=\"139\" \/><\/p>\n<p>Continuing the same example as above, here we are executing the &#8220;Force run to Cursor&#8221; using the green glyph button.<\/p>\n<p><img decoding=\"async\" class=\"wp-image-233257 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2021\/07\/text-description-automatically-generated.gif\" alt=\"Text Description automatically generated\" width=\"520\" height=\"358\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2>Special notes<\/h2>\n<p>To pause at the &#8220;Force Run To Cursor&#8221;, 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.<\/p>\n<p>The program can also stop sooner if an unhandled exception occurs before reaching that line.<\/p>\n<p>You can also get out of the \u201cForce Run To Cursor\u201d mode when you either:<\/p>\n<ul>\n<li>Stop debugging<\/li>\n<li>Hit an exception after reenabling<\/li>\n<li>Select Break all (I.e., select pause button on the toolbar)<\/li>\n<li>Hit a new breakpoint<\/li>\n<li>Hit an existing breakpoint after reenabling it<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h2>Wrap up<\/h2>\n<p>&#8220;Force Run To Cursor&#8221; provides a convenient way of debugging your application when you want to skip your breakpoints. Try it out by downloading <a href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/vs2022\/\">Visual Studio Preview 2 <\/a>now. Please drop your questions and comments in the section below or share your feedback at <a href=\"https:\/\/developercommunity.visualstudio.com\/search?space=8\">Developer Community<\/a> or tweet\u00a0<a href=\"https:\/\/twitter.com\/vs_debugger\" target=\"_blank\" rel=\"noopener\">@VS_Debugger<\/a>.\n<div  class=\"d-flex justify-content-center\"><a class=\"cta_button_link btn-primary mb-24\" href=\"https:\/\/aka.ms\/vs2022preview\" target=\"_blank\">Download Visual Studio 2022 Preview<\/a><\/div><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Starting Visual Studio 2022 Preview 2 you can use &#8220;Force Run To Cursor&#8221;. It is like &#8220;Run To Cursor,&#8221; 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.<\/p>\n","protected":false},"author":26573,"featured_media":233256,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"image","meta":{"_acf_changed":false,"footnotes":""},"categories":[155],"tags":[6793,9,6819,634,12,6815],"class_list":["post-233252","post","type-post","status-publish","format-image","has-post-thumbnail","hentry","category-visual-studio","tag-debugger","tag-debug","tag-navigate-through-code","tag-preview","tag-visual-studio","tag-visual-studio-2022","post_format-post-format-image"],"acf":[],"blog_post_summary":"<p>Starting Visual Studio 2022 Preview 2 you can use &#8220;Force Run To Cursor&#8221;. It is like &#8220;Run To Cursor,&#8221; 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.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/233252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/users\/26573"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=233252"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/233252\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/233256"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=233252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=233252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=233252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}