银光网络服务

3
以下是我在SilverLight中使用的代码来调用Web服务。
private void button1_Click(object sender, RoutedEventArgs e)
{
      BasicHttpBinding bind = new BasicHttpBinding();
      EndpointAddress endpoint = new EndpointAddress("http://loalhost/Service.asmx");
      ServiceSoapClient client = new ServiceSoapClient(bind, endpoint);
      client.RunHelloCompleted += new EventHandler<RunHelloCompletedEventArgs>(client_RunQwinCompleted);
      client.RunHelloAsync(command);
 }

 void client_RunHelloCompleted(object sender, RunHelloCompletedEventArgs e)
 {
      txtProcess.Text=Process(e.Result);
 }

我想知道一种方法,在运行RunHelloAsync(Command)后,不需要进入Completed事件就能获取返回的结果。请给我建议。谢谢。

为什么你不能在完成事件中做你需要的事情? - AnthonyWJones
1个回答

3
简单的回答:你无法做到。在Silverlight中,一切都是异步的,所以没有办法在client.RunHelloAsync(command)调用之后阻塞并等待结果。
长篇回答:有一些方法可以模拟同步方式处理异步调用,但调用仍然是异步的。请参考这个线程获取更多答案。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接