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