WeakEventManager Class
Collapse the table of content
Expand the table of content

WeakEventManager Class


Provides a base class for the event manager that is used in the weak event pattern. The manager adds and removes listeners for events (or callbacks) that also use the pattern.

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

public abstract class WeakEventManager : DispatcherObject


Initializes base class values when it is used as the initializer by the constructor of a derived class.


Gets the Dispatcher this DispatcherObject is associated with. (Inherited from DispatcherObject.)


Gets or sets the data being stored for the specified source.


Establishes a read-lock on the underlying data table, and returns an IDisposable.


Establishes a write-lock on the underlying data table, and returns anIDisposable.


Determines whether the calling thread has access to this DispatcherObject.(Inherited from DispatcherObject.)

System_CAPS_protmethodDeliverEvent(Object, EventArgs)

Delivers the event being managed to each listener.

System_CAPS_protmethodDeliverEventToList(Object, EventArgs, WeakEventManager.ListenerList)

Delivers the event being managed to each listener in the provided list.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Returns the WeakEventManager implementation that is used for the provided type.


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Creates a shallow copy of the current Object.(Inherited from Object.)


Returns a new object to contain listeners to an event.

System_CAPS_protmethodProtectedAddHandler(Object, Delegate)

Adds the specified delegate as an event handler of the specified source.

System_CAPS_protmethodProtectedAddListener(Object, IWeakEventListener)

Adds the provided listener to the provided source for the event being managed.

System_CAPS_protmethodProtectedRemoveHandler(Object, Delegate)

Removes the previously added handler from the specified source.

System_CAPS_protmethodProtectedRemoveListener(Object, IWeakEventListener)

Removes a previously added listener from the provided source.

System_CAPS_protmethodPurge(Object, Object, Boolean)

Removes inactive listener entries from the data list for the provided source. Returns true if some entries were actually removed from the list.


Removes all listeners for the specified source.


Requests that a purge of unused entries in the underlying listener list be performed on a lower priority thread.

System_CAPS_protmethodSystem_CAPS_staticSetCurrentManager(Type, WeakEventManager)

Sets the current manager for the specified manager type.


When overridden in a derived class, starts listening for the event being managed. After the StartListening method is first called, the manager should be in the state of calling DeliverEvent or DeliverEventToList whenever the relevant event from the provided source is handled.


When overridden in a derived class, stops listening on the provided source for the event being managed.


Returns a string that represents the current object.(Inherited from Object.)


Enforces that the calling thread has access to this DispatcherObject.(Inherited from DispatcherObject.)

You typically use the weak event pattern when the event source has an object lifetime that is independent of the event listeners. Using the central event dispatching capability of a WeakEventManager allows the listener's handlers to be garbage collected even if the source object persists. By contrast, a regular event hookup using the += operator causes the potentially disconnected source to hold a reference to the listeners. This prevents the receiver from being garbage collected in a timely fashion.

One common situation where the lifetime relationships between sources and listeners should use of the weak event pattern is the handling of update events coming from data bindings.

The weak event pattern can also be used for callbacks and regular events.

Notes to Inheritors:

For an example of a custom WeakEventManager, see Weak Event Patterns.

.NET Framework
Available since 3.0

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
© 2015 Microsoft