Listens to a safe class event?

base.event += this.EventHandler() 

is this code safe? will it leak?

+4
source share
3 answers

It’s best practice to override the method that fires the event, for example:

 protected override OnClick(object sender,EventArgs e) { base.OnClick(sender,e); // Your code here, or before the base call depending how you want it to operate } 

Of course, if he does not offer you this method (although this is true), you will have to stick with the binding to the Event itself.

+1
source

Listening for base class events is safe for code and does not cause memory leaks.

You can look HERE to do it right.

+2
source

Yes, that’s fine, because essentially you are just creating a link to yourself.

You only need to worry about a memory leak if you are creating an event from an external object.

+1
source

Source: https://habr.com/ru/post/1309637/


All Articles