Weak​Event​Manager Class

Definition

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.

public abstract class WeakEventManager : System.Windows.Threading.DispatcherObject
Inheritance
WeakEventManager
Derived

Inherited Members

System.Object

System.Windows.Threading.DispatcherObject

Remarks

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.

Constructors

Weak​Event​Manager()

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

Properties

Item[​Object]

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

Read​Lock

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

Write​Lock

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

Methods

Deliver​Event(​Object, ​Event​Args)

Delivers the event being managed to each listener.

Deliver​Event​To​List(​Object, ​Event​Args, ​Weak​Event​Manager+​Listener​List)

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

Get​Current​Manager(​Type)

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

New​Listener​List()

Returns a new object to contain listeners to an event.

Protected​Add​Handler(​Object, ​Delegate)

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

Protected​Add​Listener(​Object, ​IWeak​Event​Listener)

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

Protected​Remove​Handler(​Object, ​Delegate)

Removes the previously added handler from the specified source.

Protected​Remove​Listener(​Object, ​IWeak​Event​Listener)

Removes a previously added listener from the provided source.

Purge(​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.

Remove(​Object)

Removes all listeners for the specified source.

Schedule​Cleanup()

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

Set​Current​Manager(​Type, ​Weak​Event​Manager)

Sets the current manager for the specified manager type.

Start​Listening(​Object)

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

Stop​Listening(​Object)

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