2012-06-14 148 views
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; 
    } 

我知道这是一个同步/异步问题。但我不知道如何处理它。

在此先感谢。

+0

代码似乎很好,请检查您的Url是否有效? – nkchandra

+0

我认为这是相似的:http://stackoverflow.com/questions/10521232/webclients-downloadstringcompleted-event-handler-not-firing 但是,没有解决方案是在该职位给出。该网址没有问题。 – yorkzhang

回答

0

我已经用2个不同的URL http://riktamtech.comhttp://google.com测试了您的代码的WebClient部分。在这两种情况下,都会引发DownloadStringCompleted事件。我通过放置一个断点来观察它。

所以我建议你再次测试中断点。