【发布时间】:2011-06-27 08:52:45
【问题描述】:
您好,
我正在尝试使用以下代码下载网页:
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 循环正在旋转,但 result 的值从未被更新。控制台是一个文本框。对可能发生的事情有什么想法吗?
谢谢,
调频
【问题讨论】:
标签: c# windows-phone-7 webclient webclient-download