I have the following situation. I want to execute 6 URL request (each request is with different auth_token and returns different data ). Here is the function that is making requests for different auth_token.
private static async Task<List<Positions>> GeneratePositions(string auth_token)
{
var request = WebRequest.Create(www.some_url.com);
request.Headers.Add("authorization", "Bearer " + auth_token);
request.Method = "GET";
WebResponse response = null;
try
{
response = await request.GetResponseAsync();
}
catch (Exception ex)
{
// TODO log
throw ex;
}
var dataStreamRes = response.GetResponseStream();
var reader = new StreamReader(dataStreamRes);
var buffResponse = await reader.ReadToEndAsync();
var positions = JsonSerializer.Deserialize<List<Positions>>(buffResponse);
reader.Close();
dataStreamRes.Close();
response.Close();
return positions;
}
This function is ran using await
operator. But the problem is that every requests waits for the previous one to start.
Do you have any idea how I can run multiple requests for multiple auth_tokens at the same time, without waiting the previous one to finish, and of course collect the data returned.