Using the Action Generic Delegate for callbacks



When creating a new subscriber interface for a WCF service recently I discovered this elegant little pattern “firing” a list of Action generic Delegates. Basically for each subscriber it calls the anonymous method



// create a delegate for the call back to fire
Action<ILogBookSubscriberCallback> fire = delegate(ILogBookSubscriberCallback callback)


{
callback.OnNewEntry(entry);
};


// fore the delegate for each in the list
m_callBacks.ForEach(fire);


Incidentally I found this nice article on Using Callback Contracts in WCF

Comments (0)