I came upon some code in an application I’m supposed to update that defines an event handler for every possible event of a control (or at least all of the ones listed in the designer, from what I can tell). I’ve never seen this before and have no desire to implement it in any of my applications.
One example; a button that starts a logging operation begins the operation on Click. However, all other event handlers are also bound, from AutoSizeChanged and BackColorChanged right down to VisibleChanged and Validating. With the exception of Click, all event handlers are empty. From what I can tell so far, this happens with many controls throughout the application.
No comments are provided detailing why this is the case either. Why would this be done?
Most likely because the original author didn’t understand that it was not necessary.
There is no good technical reason to do this. It actually just decreases performance, and provides no benefit.
Note that many people, when they create an event on their own class, often subscribe an empty event handler. This makes it so they can avoid the null check on the subscription list. I suspect this was done as a misguided attempt to prevent that, even though it’s typically done on the event publishing side, not the subscription side of the equation.