Provides event listening support for classes that expect to receive events through the WeakEvent pattern and a WeakEventManager.
Assembly: WindowsBase (in WindowsBase.dll)
Thetype exposes the following members.
The WeakEventManager (a dispatcher) forwards an event by calling the ReceiveWeakEvent method on classes that implement this interface, and that have been added as listeners by calling WeakEventManager methods beforehand.
The principal reason for following the WeakEvent pattern is when the event source has an object lifetime that is potentially independent of the event listeners. Using the central event dispatching of a WeakEventManager enables the handlers for listeners to be garbage collected (or manually purged) even if the source object lifetime extends beyond the listeners. By contrast, a normal event hookup using += or equivalent language-specific event syntax causes the potentially still-connected source to hold a strong reference to the handlers. This keeps the listener references from being garbage collected in a timely fashion.
One common situation where the relationships between sources and listeners suggests the use of this pattern is the handling of update events coming from sources for data bindings.
You can use the WeakEvent pattern to listen for events that are external to your application. You only need to define a WeakEventManager for it, provide listening behavior in ReceiveWeakEvent, and use the WeakEventManager to attach the handler references rather than +=.