0
我正在开发一个Windows Phone应用程序。 Web客户端不会像我预期的那样开启。相关代码如下:DownloadStringCompleted事件不会触发
public PArticle(PocketListItem aPli)
{
this.pli = aPli;
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!isf.FileExists(aPli.ID + ".json"))
{
WebClient client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadStringAsync(new Uri(pli.Url));
}
else
{
string json = RetrieveDataFromLocalStorage(aPli.ID + ".json");
PocketArticle pa = JsonConvert.DeserializeObject<PocketArticle>(json);
this.text = pa.text;
}
}
}
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
var readability = Readability.Create(e.Result);
this.text = readability.Content;
}
我知道这是一个同步/异步问题。但我不知道如何处理它。
在此先感谢。
代码似乎很好,请检查您的Url是否有效? – nkchandra
我认为这是相似的:http://stackoverflow.com/questions/10521232/webclients-downloadstringcompleted-event-handler-not-firing 但是,没有解决方案是在该职位给出。该网址没有问题。 – yorkzhang