如何等待Wp7 UI直到获得Web请求响应 [英] how to wait Wp7 UI until get web request response

查看:78
本文介绍了如何等待Wp7 UI直到获得Web请求响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然在Windows Mobile中等待响应,但是不幸的是我的UI线程不等待响应...(银色指示灯不支持同步线程)

如何同步这种情况?

如何停止我的UI线程,直到获得响应?

等待快速回复........

While waiting for the response in Windows mobile but unfortunately my UI thread doesn''t wait for the response ...( silver light doesn''t supported synchronous thread )

How can i synchronize this situation ?

How can i stop My UI thread until get response ?

Waiting for fast reply ........

推荐答案

您不想让UI线程等待它得到响应(在实际上,通常在UI线程上完成的处理方式很少.您调用异步函数,并让UI(以适当的方式)通知用户您正在使用它.

当调用该函数开始请求时,必须提供一个回调,在收到响应后将调用该回调.该回调可能将在后台线程上,然后该线程可以继续处理并根据需要更新UI(根据需要使用Dispatcher.Invoke).

这样,您就可以维护一个响应式UI(因此您的用户和Windows都不会认为您的程序已崩溃),并且通常对您的用户更好(这意味着您可以同时进行其他操作).请记住,正是由于这个原因,在Silverlight中,您编写的许多事件处理程序也都在后台线程上运行.
You don''t want to have your UI thread wait until it get''s a response (in fact, very little in the way of processing normally gets done on the UI thread). You call the asynchronous function, and have you UI inform the user (in whatever way appropriate) that you''re working on it.

When you call the function to begin the request, you have to provide a callback which will get called when the response has been received. This callback will probably be on a background thread, which can then continue the processing and update the UI as required (using Dispatcher.Invoke as required).

Doing it this way allows you to maintain a responsive UI (so neither your user nor Windows think your program has crashed) and is generally nicer for your user (also means you can get on with something else in the meantime, if needed). Keep in mind that in Silverlight, many of the event handlers you write also run on a background thread for exactly this reason.


这篇关于如何等待Wp7 UI直到获得Web请求响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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