本文介绍了对 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 服务的异步请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!