Raising Multiple Events

If your class raises multiple events and you program these as described in Raising an Event, the compiler generates one field per event delegate instance. If the number of events is large, the storage cost of one field per delegate may not be acceptable. For those situations, the .NET Framework provides a construct called event properties (custom events in Visual Basic 2005) that you can use together with another data structure (of your choice) to store event delegates.

Event properties consist of event declarations accompanied by event accessors. Event accessors are methods you define to allow event delegate instances to be added or removed from the storage data structure. Note that event properties are slower than event fields, as each event delegate must be retrieved before it can be invoked. The trade-off is between memory and speed. If your class defines many events that are infrequently raised, you will want to implement event properties. Windows Forms controls and ASP.NET server controls use event properties instead of event fields.

See Also

Tasks

How to: Handle Multiple Events Using Event Properties

How to: Declare Custom Events To Conserve Memory (Visual Basic)

Reference

System.ComponentModel.EventHandlerList

System.Web.UI.Control.Events

Other Resources

Handling and Raising Events