I have several pseudo-global entities in my Silverlight application that are populated with data from the server. My ‘service agent’ class is registered with the IoC container as a singleton so it will cache the data to prevent excessive calls to the server.
However, I’m running into a scenario where multiple requests are being made to the ‘service agent’ while the initial request is still pending. While I look into other design issues contributing to the situation, I’m wondering what ideas you may have how to handle this. My initial thought is to somehow queue the requests if a call is already in progress then handle them when the data is retrieved.
I ended up going with the queue and lock approach after all. I have a ‘busy’ flag that indicates a service call is in-progress. When true, all subsequent requests are queued by adding the callback delegate to a collection and the method returns. When the async service call returns, I simply iterate through the collection and execute each callback. It seems to work pretty good (in an async model).