tags:

views:

57

answers:

3
base.event += this.EventHandler()

is this code safe ? will it cause a leak ?

+2  A: 

Listening to base class events is code safe, won't cause memory leaks.

You can have a look HERE to do it properly, though.

thelost
+1  A: 

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.

Mongus Pong
A: 

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.

Chris S