Silverlight中的异步调用 [英] Asynchronous call in silverlight

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

问题描述


我有一个正在使用WCF的Silverlight3应用程序.我正在从Silverlight应用程序递归调用wcf中定义的一项服务.

问题是-我在这里面临的问题是,在获得第一个调用的结果之前,它正在激活第二个调用.所以有时候我会得到第二个Call(对wcf的调用)的结果,因为会得到第一个Call的结果.我知道Silverlight仅支持同步通话.但是在这种情况下,我该如何处理程序流程.

详细信息如下:

Hi
I have a Silverlight3 application whcih is using WCF. I am calling one service which is defined in the wcf from my silverlight application recursively.

The problem is - here I am facing is that before getting the result of the first call, it is activating the second call. So some times I am getting the result of the second Call(call to wcf) befor getting the result of first call. I know that silverlight support only Sync call. But in this situation how I can handle the program flow.

Here is the details:

Silverlight appln
{
//Recursive call
    while(i<3)
    {
    callWCFAsync() //
    //do some work-- Here I want to do some work based on the result of 1 call, then based on the result of 2 call, then based on the result of 3 call(otherwise it should invoke the second call(in second iteration),only after getting the result of first call)-- How I can achieve it....??
    }
}

WCF
{
definition of callWCFAsync()
{
}
}


请帮助我.

在此先感谢... :):)


Please help me on this.

Thanks in Advance... :) :)

推荐答案

这很简单.仅当对第一个服务的调用返回时,才调用第二个服务.这是确保第二个开始在SL中的异步调用中开始执行时,第一个调用的结果可用的唯一方法.

祝你好运!
This is very easy. Call the second service only when the call to the first service returns. This is the only way to guarantee you have the results for the first call available when the second one starts execution in asynchronous calls in SL.

Best of luck!


我写了一篇关于这个的文章:

我如何优化Silverlight异步Web服务的使用量 [
I wrote an article about this:

How I Optimized my Silverlight Asynchronous Web Service Consumption[^]


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

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