Using Synchronized Events

The AsSend() method is extended to EventHandler<> derivatives, PropertyChangingEventHandler and PropertyChangedEventHandler. It checks whether the thread calling AsSend has a SynchronizationContext. If it does, then the delegate is wrapped so that it is always called on the same SynchronizationContext, thus simplifying GUI programming.
        var propertyChangingHandler = new PropertyChangingEventHandler(listener.HandleChange);
        observable.PropertyChanging += propertyChangingHandler.AsSend();
        // listener.HandleChange will always be invoked on this thread


Last edited Oct 28, 2010 at 6:43 PM by maranite, version 2

Comments

No comments yet.