**Developer**,
As Mattias suggests, its used to prevent a lot of allocations of EventArgs
objects, which have no mutable attributes. Preventing the allocations should
help performance, as the GC won't need to work as much...
Creating a shared readonly property or field called "Empty" is a common
pattern used in the framework for Immutable types. For example:
- String.Empty
- EventArgs.Empty
- Match.Empty
- Color.Empty
Its used whenever there is an "default instance" that can/should be used
instead of allocating a new instance of the class. In the case of a
structure, its useful to have an uninitialized ("Empty") value of the
structure.
--
Hope this helps
Jay [MVP - Outlook]
T.S. Bradley -
http://www.tsbradley.net
" **Developer**" <RE*************@a-znet.com> wrote in message
news:uV**************@TK2MSFTNGP15.phx.gbl...
| I've been reading the Help Doc and am confused about the Empty field.
| Which is type EventArgs.
| What is that all about?
|
|
|
|
|
| "Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> wrote in
| message news:uI**************@TK2MSFTNGP14.phx.gbl...
| > Doh!!
| >
| > That should be:
| > | Protected Overridable Sub OnSomeNotification(ByVal e As EventArgs)
| > | RaiseEvent SomeNotification(Me, e)
| > | End Sub
| >
| > Obviously the OnSomeNotification raises the SomeNotification event & not
| > the
| > AbortAll event as I showed. ;-)
| >
| > --
| > Hope this helps
| > Jay [MVP - Outlook]
| > T.S. Bradley -
http://www.tsbradley.net
| >
| >
| > "Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.net> wrote in
| > message news:ex**************@TK2MSFTNGP12.phx.gbl...
| > | **Developer**
| > | In addition to the other comments:
| > |
| > | I normally define my events as:
| > |
| > | Public Event SomeNotification As EventHandler
| > |
| > | As EventHandler is a Delegate that is defined with the sender & e
| > | parameters. Indirectly this minimizes the number of Delegates that are
| > | defined. If you define your event as:
| > |
| > | Public Class Something
| > | Public Event SomeNotification (ByVal sender As Object, ByVal e
As
| > | EventArgs)
| > | End Class
| > |
| > | Then VB creates a hidden Delegate for you, which you see in ILDASM.EXE
| > as
| > | Something.SomeNotificationEventHandler.
| > |
| > | If you have a lot of events like SomeNotification, then you wind up
with
| > a
| > | lot of Delegate types that are defined identically, leading to
Assembly
| > | bloat...
| > |
| > |
| > | I normally call an OnSomeNotification sub to raise the event.
| > |
| > | OnSomeNotification(EventArgs.Empty)
| > |
| > | When I raise the event, where OnSomeNotification is defined as:
| > |
| > | Protected Overridable Sub OnSomeNotification(ByVal e As EventArgs)
| > | RaiseEvent AbortAll(Me, e)
| > | End Sub
| > |
| > | Using OnSomeNotification allows derived classes to both raise the
event
| > &
| > to
| > | add code before and/or after the event is raised. Normally I simply
| > override
| > | OnSomeNotification to allow a derived class to simply handle the
event,
| > | rather then using AddHandler...
| > |
| > |
| > | The above event pattern is defined at:
| > |
| > |
| >
http://msdn.microsoft.com/library/de...guidelines.asp
| > | and
| > |
| >
http://msdn.microsoft.com/library/de...Guidelines.asp
| > |
| > |
| > | --
| > | Hope this helps
| > | Jay [MVP - Outlook]
| > | T.S. Bradley -
http://www.tsbradley.net
| > |
| > |
| > | " **Developer**" <RE*************@a-znet.com> wrote in message
| > | news:e%****************@TK2MSFTNGP12.phx.gbl...
| > ||I always define events with the parameters
| > ||
| > || ByVal sender As Object, ByVal e As EventArgs
| > ||
| > || Even if they are not used.
| > ||
| > || Seems I read someplace that's the thing to do.
| > ||
| > || So I then do:
| > ||
| > || RaiseEvent AbortAll(Nothing, Nothing)
| > ||
| > || Does that make sense to you?
| > ||
| > || Is that the standard practice?
| > ||
| > ||
| > ||
| > ||
| > ||
| > || Thanks
| > ||
| > ||
| > |
| > |
| >
| >
|
|