开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜