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 +=.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.