Is it possible to set a breakpoint in anonymous functions?

Steven Jeuris picture Steven Jeuris · Sep 6, 2012 · Viewed 11.4k times · Source

I quickly want to determine whether/when a set of events are triggered. Therefore I quickly assigned empty lambda's to them.

_session.TopologyStarted += () => { };

When tracing through the code when the event is triggered, the debugger goes into the anonymous function, allowing to debug it's execution. However, when setting a breakpoint on this line of code, a breakpoint is set on the assignment of the anonymous function to the event.

Is there a way to set a breakpoint within the anonymous function?

Answer

Martin Ernst picture Martin Ernst · Sep 6, 2012

Put your cursor in the anonymous function (between the {}'s) and press F9.