public AddedEventDispatcher(Collection <V> collection, EventQueue dispatcher, AddedEventHandler handler) { this.Collection = collection; this.Handler = dispatcher != null ? delegate(Collection <V> .AddedEventArgs args) { dispatcher.Post(delegate() { handler(args); }); } : handler; this.Collection.Added += this.Handler; }
public void Dispose() { AddedEventHandler handler = Interlocked.Exchange(ref this.Handler, null); this.Collection.Added -= handler; }
public IDisposable Listen(EventQueue dispatcher, AddedEventHandler handler) { // The AddedEventDispatcher constructor adds an event handler to the Added event. return(new AddedEventDispatcher(this, dispatcher, handler)); }