Click or drag to resize

WeakEventController Class

Implements a weak event listener that allows the owner to be garbage collected if it is the only remaining link is an event handler.
Inheritance Hierarchy

Namespace:  System
Assembly:  Neon.Common (in Neon.Common.dll) Version: 2.14.0
public static class WeakEventController

The WeakEventController type exposes the following members.


This class is intended to be a drop-in replacement for the WeakEventManager class that is available in .NET 4.5 but is not currently present in the Xamarin Mono class libraries. Use the AddHandlerTEventSource, TEventArgs(TEventSource, String, EventHandlerTEventArgs) and RemoveHandlerTEventSource, TEventArgs(TEventSource, String, EventHandlerTEventArgs) to add or remove event handlers.

Note Note
Important: Take care to remove any handlers when an event listener instance is disposed and/or finalized. Neglecting to do this will orhpan the objects WeakEventController uses to track the handler references.

This code was adapted from a Code Project article by Samuel Cragg called WeakEventManager for WinRT. The code is licensed under the The Code Project Open License (CPOL).

I enhanced the code by making it threadsafe.

See Also