I understood that Handles is only one way to add in constructor the AddHandler, but in general are these two are equivalent?
I understood that Handles is only one way to add in constructor the AddHandler
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is some difference in exactly when the event handler is attached, and what is going on around it. For instance, when using
WithEventsandHandles, the compiler will emit code that wraps access to the variable holding the instance that exposes the event in a property, and inside the property setter it will detach the event handler from the previous instance (if any), and then attach the event handler to the new instance (if any).This means that if you take the following code samples, the access to
mmwill behave differently:In the
WithEventscase,mm = New SomeClass()will in fact call a property setter, andDim nn As SomeClass = mmwill fetch the value from a property getter, while in the second case, there will be no property created for the value, but the code will access the field directly.