Export (0) Print
Expand All

IWeakEventListener Interface

Provides event listening support for classes that expect to receive events through the WeakEvent pattern and a WeakEventManager.

Namespace:  System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)

public interface IWeakEventListener

The IWeakEventListener type exposes the following members.

  NameDescription
Public methodReceiveWeakEventReceives events from the centralized event manager.
Top

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 +=.

.NET Framework

Supported in: 4.5.3, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

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.

Show:
© 2014 Microsoft