Tracking Event Handler Registrations

When working with large .Net applications, it can be useful to find out where event handlers are being registered, especially in an unfamiliar codebase.

In simple cases, you can do this by right-clicking the event definition and clicking Find All References (Shift+F12).  This will show you every line of code that adds or removes a handler from the event by name.  For field-like (ordinary) events, this will also show you every line of code that raises the event.

However, this isn’t always good enough.  Sometimes, event handlers are not added by name.  The .Net data-binding infrastructure, as well as the CompositeUI Event Broker service, will add and remove event handlers using reflection, so they won’t be found by Find All References.  Similarly, if an event handler is added by an external DLL, Find All References won’t find it.

For these scenarios, you can use a less-obvious trick.  As I described last time, adding or removing an event handler actually executes code inside of an accessor method. Like any other code, we can set a breakpoint to see where the code is executed.

For custom events, this is easy.  Just add a breakpoint in the add and/or remove accessors and run your program.  Whenever a handler is added or removed, the debugger will break into the accessor, and you can look at the callstack to determine where it’s coming from.

However, most events are field-like, and don’t have actual source code in their accessor methods.  To set a breakpoint in a field-like event, you need to use a lesser-known feature: function breakpoints (Unfortunately, this feature is not available in Visual Studio Express).  You can click Debug, New Breakpoint, Break at Function (Ctrl+D, N) to tell the debugger to pause whenever a specific managed function is executed.

To add a breakpoint at an event accessor, type Namespace.ClassName.add_EventName.  To ensure that you entered it correctly, open the Debug, Breakpoints window (Ctrl+D, B) and check that the new breakpoint says break always (currently 0) in the Hit Count column.  If it doesn’t say (currently 0), then either the assembly has not been loaded yet or you made a typo in the location (right-click the breakpoint and click Location).


Thanks for this useful info


The above article is nice and interesting, thank you willing to share! Greetings success of admin Percetakan Murah Rawamangun Jakarta Timur wish you deign to visit my website, thank you :)

You should definitely check this out if you want to know more about homework cheats. It will help you for sure

This comment has been removed by the author.

I didn't know much about this. I am new to .Net and wants to work on its framework so can you please give details that how to create event handlers for cheap nursings assignment Help - and how can we easily track them out?

Saints 2 Clean is the best residential cleaning service providing exceptional services that don’t have the time to do not have the time. We make sure to maintain a healthy and clean environment for your place at a cost-effective pricing range. Visit our website for comprehensive information on our services and cost-effective packages.

I am searching for this kind of post so fortunately got this. One of my friends writing blogs on different categories including kitchen items such as toasters and toaster ovens to make the branded items more accessible. These blogs are also helpful for customers before buying their favorite items.

Ooh, this is something going over my head, but one of my friend who is an app develop and use .Net can take help from this. As he once helped me in Qualitative Research Transcription UK standard, and now, I want to pay back him with some useful stuff for his work.

Event handlers are something that happens when an event occurs. It runs out when just for the duration of an even occurs and affordable rates vinyl flooring in karachi offering services for long terms.

For Like any other code, we can set a breakpoint to see where the code is executed.
these scenarios, you can use a less-obvious trick. As I described last time, adding ordissertation writing services available for a complete dissertation including all chapters from introduction,
Dissertation Writing Services

I really want to work with .Net applications, but unfortunately, the version I want to use is not supported anymore by Microsoft. Cheap Dissertation Writing Service

Post a Comment