Domanda

I'm playing with the most simplest case of usage bcl.async in wp7.

private async void loadButton_Click1(object sender, RoutedEventArgs e)
{
        var client = new WebClient(); 
        string response = await client.DownloadStringTaskAsync(new Uri("myurl"));
        Debug.WriteLine(response);
}

So, i have breakpoints on the first and last lines, running in on device in debug mode. Sometimes it takes about 5 seconds to get the answer (which is weird), but sometimes it takes almost minute. During 1 request from device, i'm able to check request in the browser (getting instant answer, less than second), got some tea, and check 9gag.

I can assume that i have bad networking, but browser's request is lightspeed, so that is not a problem. Also, i tried RestSharp, but faced the same issue. Non-async WebClient calls work fine.

EDIT: FAST SOLUTION: very first thing you want to do is to restart device.

È stato utile?

Soluzione

As I mentioned in the comment I think it would be worth looking into using HttpClient rather than WebClient. HttpClient is newer and designed with the new WebAPI in mind and I believe designed to work with greater efficiency in general.

There is a good comparison listed here.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top