Re: Consuming your own events.
Daniel Petersson <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.clr |
|---|---|
| Message-ID | <E8FBCCA96548DD46A1AC748F17EEAD9C0E96F6F4E7@cefalo-mail01.cefalo.local> |
the guideline clearly state that non-sealed classes that expose events should implement a: protected virtual void OnTheEvent( EventArgs e ) for every public event. I wuold strongly recomend any inheritor to override the OnTheEvent( ... ) instead of a "lazy" +=. Through this override you can control ordering (as mentioned earlier) but you can also cancel the event if required. The performance aspect can be neglected since the invokation cost of a method and delegates are almost identical. (prior to CLR2.0 there where a performance issue with delegate invocation) regards, Daniel ________________________________________ From: Discussion of development on the .NET platform using any managed language [[email protected]] On Behalf Of Greg Young [[email protected]] Sent: Monday, January 28, 2008 11:30 PM To: [email protected] Subject: Re: [DOTNET-CLR] Consuming your own events. I agree with Sebastien here ...but there is a problem that can be introduced with ordering (when it is changed)... when do I need to tie the event in order to be able to use it? With the overriden template methods this problem doesn't exist. On Jan 28, 2008 2:25 PM, Sebastien Lambla <[email protected]> wrote: > > I've definitely fixed bugs in the last year by *removing* the event > > handler and installing this pattern. The documentation does say > > (somewhere) that for certain events such as Load, a class's behavior > > will be undefined if it listens for the event on itself. > > This is not a CLR issue though, but a classlib design. If your class can > have undefined behaviour if someone forgets to call the base class > implementation, you either have a weak documentation or a weak > implementation. Maybe both. > > > > > -----Original Message----- > > From: Discussion of development on the .NET platform using any managed > > language [mailto:[email protected]] On Behalf Of Greg > > Young > > Sent: Monday, January 28, 2008 2:42 PM > > To: [email protected] > > Subject: Re: [DOTNET-CLR] Consuming your own events. > > > > Events are slower than a simple virtual method call ... also if there > > is > > an exception in another event handler your code is not guarenteed to be > > called where as with the OnXXX pattern (event template methods) your > > code will be called before the event is actually raised. > > > > On Jan 28, 2008 8:59 AM, Brady Kelly <[email protected]> wrote: > > > I came across a mention in an article last year, advising on not > > > consuming your own events, e.g. not using a Form_Load handler on your > > > form, but overriding OnLoad. What is the story behind this, and is > > it > > > > > a UI thing I should ask about elsewhere, or a more general pattern? > > > > =================================== > > This list is hosted by DevelopMentor. http://www.develop.com > > > > View archives and manage your subscription(s) at > > http://discuss.develop.com > > =================================== > This list is hosted by DevelopMentor(R) http://www.develop.com > > View archives and manage your subscription(s) at http://discuss.develop.com > -- Studying for the Turing test =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com