异步请求到Web服务 [英] Async requests to a web service

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

问题描述

如何从线程向Web服务发出异步请求?

How to make async requests to a webservice from a Thread?

推荐答案

这是简短的答案,没有很多解释.

Here is the short answer without a load of explanations.

在对Client对象调用Async方法之前,请确保未在UI线程上运行:-

Before calling the Async method on your Client object make sure you are not running on the UI Thread:-

System.Threading.ThreadPool.QueueUserWorkItem( o =>
{
   try
   {
      svc.SomeMethodAsync();
   }
   catch (err)
   {
       // do something sensible with err
   }
});

现在,相应的完成事件将在ThreadPool线程而不是UI线程上发生.

Now the corresponding completed event will occur on a ThreadPool thread not the UI Thread.

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

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