0

I am developing a windows phone application. The webclient does not fire as I expected. The related code is as below:

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;
    }

I know it's a synchronous/asynchronous problem. But I have no idea about how to handle it.

Thanks in advance.

yorkzhang
  • 17
  • 1
  • 5
  • Code seems to be fine, check whether your Url is valid or not? – nkchandra Jun 14 '12 at 09:09
  • I think it is smilar to :http://stackoverflow.com/questions/10521232/webclients-downloadstringcompleted-event-handler-not-firing However, no solution is given in that post. The url has no problems. – yorkzhang Jun 14 '12 at 09:14

1 Answers1

0

I have tested the WebClient part of your code with 2 different URLs http://riktamtech.com and http://google.com. In both cases, the DownloadStringCompleted event is raised. I observed it by placing a break point.

So I suggest you to test again with break points.

nkchandra
  • 5,585
  • 2
  • 30
  • 45