Run code on hit breakpoint?

In the Immediate window, I can execute a line of code. I can also set a breakpoint at a specific point so that when the breakpoint is reached, the program stops, and I can run my line of code in the Immediate window. Is there a way (extensions included) to do this automatically?

+8
c # visual-studio-2012
source share
1 answer

More or less. You can click any breakpoint and select "When Hit ...".

The only option is to print a message, which is usually enough, but you can run arbitrary code there. For example: {Console.WriteLine("Hello World")}

Screenshot of Visual Studio When-Hit breakpoint

This will output:

Hello World
The expression has been evaluated and does not matter.

This means that you can call arbitrary methods. Any other side effects will be transferred to your application. I sometimes use it to temporarily fix code problems without restarting a 64-bit application.

Keep in mind that this is exceptionally slow compared to regular program execution.

+16
source share

All Articles