I have an app that making API requests to the last.fm website using the backgroundWorker. Initially I don\'t know how many request I\'m gonna need to make. The response cont
You can take advantage of HttpClient, assume you have list of urls:
var client = new HttpClient();
var tasks = urls.Select(url => client.GetAsync(url).ContinueWith(t =>
{
var response = t.Result;
response.EnsureSuccessStatusCode();
//Do something more
}));
If you use async method, you can await all tasks finish like below:
var results = await Task.WhenAll(tasks);
You can do Async Web Request as well, using BeginGetResponse
HttpWebRequest webRequest;
webRequest.BeginGetResponse(new AsyncCallback(callbackfunc), null);
void callbackfunc(IAsyncResult response)
{
webRequest.EndGetResponse(response);
}