tags:

views:

48

answers:

2

Let's say you have a custom form MyForm : Form and want to run some custom code for the OnLoad event.

Are there any performance reasons to register for the OnLoad event and run your code in the handler method instead of overriding the OnLoad method in which you call the base method and run your custom code ?

Are there any pros/cons for going one or the other way ? What would you choose and why ?

+3  A: 

MSDN page says this:

The OnLoad method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

(emphasis mine).

From performance standpoint, the difference is negligible here. Unless you have millions of subscribers, though.

Anton Gogolev
+3  A: 

Overriding the OnLoad method allows you to run code both before and after any other handlers for the event (Which are called by base.OnLoad(e), or prevent them entirely; this can sometimes be useful.

Also, I believe that it will be a tiny bit faster.

SLaks