2
问候工作,WebClient.DownloadStringAsync不是WP7模拟器
我试图下载一个网页,用下面的代码:
public partial class MainPage : PhoneApplicationPage
{
private static string result = null;
// Constructor
public MainPage()
{
InitializeComponent();
LoadFeeds();
}
public static void LoadFeedsCompleted(Object sender, DownloadStringCompletedEventArgs e)
{
result = e.Result;
}
private void LoadFeeds()
{
string url = "http://www.cornfedsystems.com";
Uri uri = new Uri(url);
WebClient client = new WebClient();
client.DownloadStringCompleted += LoadFeedsCompleted;
client.AllowReadStreamBuffering = true;
client.DownloadStringAsync(uri);
for (; ;)
{
if (result != null)
{
console.Text = result;
result = null;
}
Thread.Sleep(100);
}
}
}
此代码编译正常,但当我在模拟器启动,它只是挂在时钟屏幕上,即等待。我放入了一些断点,我可以看到for循环正在旋转,但结果的值永远不会被更新。控制台是一个TextBox。有关可能发生什么的任何想法?
感谢,
FM
感谢您的回复。这工作很好,是我见过的最简单的代码。 – 2011-02-15 05:55:30