I’ve got the following code:
WebClient client = new WebClient();
client.OpenReadAsync(new Uri("whatever"));
client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
and:
void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
Stream reply = (Stream)e.Result;
StreamReader s;
s = new StreamReader(reply);
this._code = s.ReadToEnd();
s.Close();
}
While debugging I can see the compiler doesn’t move into the client_OpenReadCompleted event. Where’s the mistake? I already tried using DownloadStringCompleted and DownloadStringAsync instead, but this doesn’t work either.
Thanks for your help.
I would advice you to not use the WebClient since this has a negative impact on your UI because the callback will always return on the UI thread because of a bug.
Here is explained why and how you can use HttpWebRequest as an alternative
http://social.msdn.microsoft.com/Forums/en-US/windowsphone7series/thread/594e1422-3b69-4cd2-a09b-fb500d5eb1d8