将 SL4 应用程序的多个请求排队到服务
我的 Silverlight 应用程序中有几个伪全局实体,它们填充了来自服务器的数据。我的“服务代理”类作为单例在 IoC 容器中注册,因此它将缓存数据以防止对服务器的过多调用。
但是,我遇到了这样一种情况:在初始请求仍处于待处理状态时,正在向“服务代理”发出多个请求。当我研究导致这种情况的其他设计问题时,我想知道您可能有什么想法来处理这个问题。我最初的想法是,如果呼叫已经在进行中,则以某种方式对请求进行排队,然后在检索数据时处理它们。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
毕竟我最终采用了队列和锁定方法。我有一个“忙”标志,表明服务呼叫正在进行中。如果为 true,则通过将回调委托添加到集合中来对所有后续请求进行排队,然后该方法返回。当异步服务调用返回时,我只需迭代该集合并执行每个回调。它似乎工作得很好(在异步模型中)。
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).