DownloadStringTaskAsync WP7上的检索结果时挂起 [英] DownloadStringTaskAsync on WP7 hangs when retrieving Result

查看:255
本文介绍了DownloadStringTaskAsync WP7上的检索结果时挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我转换了一堆WP7 code的使用DownloadStringTaskAsync而不是DownloadStringAsync使用异步CTP SP1。这不是工作,所以我归结我的code一堆并结束了与这两条线:

I converted a bunch of WP7 code to use DownloadStringTaskAsync instead of DownloadStringAsync using the Async CTP SP1. It wasn't working so I boiled down my code a bunch and ended up with these 2 lines:

var wc = new WebClient();
var result = wc.DownloadStringTaskAsync("http://www.weather.gov").Result;

如果我运行这个方法,我的Windows机器上的控制台应用程序。其作品如我所料,我得到与weather.gov的内容的字符串。如果我运行相同的2线应用的空白WP7应用程序的构造,它挂在等待结果变得可用。

If I run this method with a console app on my windows machine. Its works as I expect and I get a string with the contents of weather.gov. If I run the same 2 lines in the constructor of App in a blank WP7 app, it hangs while waiting for Result to become available.

谁能帮我解决这些行所以他们会在手机上运行?或者这是在CTP中的错误,我应该跳过它现在。

Can anyone help me fix these lines so they will work on the phone? Or is this a bug in the CTP and I should skip it for now.

推荐答案

Windows手机带回HTTP UI线程上的请求。通过访问结果,你是阻塞UI线程,从而使它不可能为了应对回来。

Windows Phone brings back HTTP requests on the UI thread. By accessing Result, you are blocking the UI thread, thus making it impossible for the response to come back.

考虑您使用的是异步CTP,你为什么要不惜一切阻止?

Considering you are using the async CTP, why would you want to block at all?

var result = await wc.DownloadStringTaskAsync("http://www.weather.gov");

这篇关于DownloadStringTaskAsync WP7上的检索结果时挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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