I prefer WithEvents / Handles in situations where it is applicable, because it better expresses what the code should do. One caveat with "WithEvents / Handles" is that any object that receives events from a longer-lived object must implement IDisposable and must set all WithEvents variables to Nothing when it is deleted so that all events are reset to zero. Disabling events when using AddHandler / RemoveHandler is necessary, but perhaps more obvious. When using WithEvents, it is somewhat easier to forget.
By the way, I do not know how to automatically set all WithEvents variables to Nothing. This would seem to be a fairly general requirement, but for some reason Microsoft did not include such a feature in VB.
supercat
source share