Assembly: WindowsBase (in windowsbase.dll)
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 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter EditionThe Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.