is listening to an event of a base class safe?
base.event += this.EventHandler()
is this code safe ? will it cause a l开发者_运维问答eak ?
Listening to base class events is code safe, won't cause memory leaks.
You can have a look HERE to do it properly, though.
It's better 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 it doesn't offer you this method (although it really should) you will have to stick to binding to the Event
itself.
Yes that is fine, as essentially you are just creating a reference to yourself.
You only need to worry about memory leaks if you create an event from an external object.
精彩评论