Is it possible to set a breakpoint in anonymous functions?

C#Visual Studio-2010LambdaAnonymous Function

C# Problem Overview


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?

C# Solutions


Solution 1 - C#

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSteven JeurisView Question on Stackoverflow
Solution 1 - C#Martin ErnstView Answer on Stackoverflow