Silverlight WCF 代理仅异步? [英] Silverlight WCF Proxy async only?

查看:26
本文介绍了Silverlight WCF 代理仅异步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 Silerlight 生成的 WCF 代理类只提供异步调用?

Why do the Silerlight-generated WCF proxy class(es) offer only async calls?

有些情况下我并不真正需要异步模式(例如在 BackgroundWorker 中)

There are cases where I don't really need the async pattern (for example in a BackgroundWorker)

有时我需要处理两个 WCF 调用的结果.如果我可以等待(应用程序的业务允许)两个调用结束然后处理,那会简单得多......但是没有......异步!:P

EDIT : Sometimes I need to process the results of two WCF calls. It would have been much simpler if I could have waited (the business of the app allows that) for both calls to end and then process.. but noooo.... async! :P

推荐答案

实际上有一个技术原因你不能进行同步调用,至少从主"浏览器线程,这是浏览器调用所有插件——在同一线程上的 API 调用中,因此如果 SL 在等待网络回调时阻塞该线程,则网络回调将无法通过,应用程序将死锁.也就是说,如果从不同的线程启动同步 API 会正常工作——即,如果应用程序首先执行 QueueUserWorkItem 以脱离浏览器线程——但我们觉得提供同步选项并只拥有它会令人困惑工作一段时间.

There's actually a technical reason you can't do sync calls, at least from the 'main' browser thread, which is that the browser invokes all the plug-in API calls on the same thread, so if SL were to block that thread while waiting for the network callback, the network callback wouldn't get through and the app would deadlock. That said, the sync API would work fine if initiated from a different thread -- ie, if the application first does a QueueUserWorkItem to get off the browser thread -- but we felt it would be confusing to offer the sync option and have it only work some of the time.

这篇关于Silverlight WCF 代理仅异步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆