i making ~20 http get requests using one httpclient, this httpclient is long living, means it is not packed into a using statement. As the webservice is normally pretty fast (response time ~200ms) i set the timeout to 5sec.
Now i ran into the problem, if one request runs into that timeout all other requests get cancelled. Is this the normal behaviour?
Here is the code i am using to make conccurent calls
public async Task GetAll()
{
await Task.WhenAll(x => x.Select(xx => GetData(xx.Id));
}
Code to call the api:
public async Task GetData(int id)
{
string payload = "";
try
{
var resp = await base.GetAsync($"/apis/v2/getdata/{id}");
if (!resp.IsSuccessStatusCode)
Console.WriteLine("Error");
payload = await resp.Content.ReadAsStringAsync();
Console.WriteLine(payload);
}
catch (System.Exception ex)
{
Console.WriteLine("Error");
}
}
My Base HttpClient Class
public class MyHttpClient : System.Net.Http.HttpClient
{
public Logger Log { get; set; }
}
If i run the task in sequential order everything works fine, but when i run them in parallel and one task runs into a timeout all other not finished task will be cancelled.
asyncmodifier. What isbasehere? What doesbase.GetAsyncdo?ServicePointManager.DefaultConnectionLimitto 20, would that fix the issue? ( because default limit is 2 in .Net Framework, reference : blogs.msdn.microsoft.com/timomta/2017/10/23/… )baseis, not sure how you think it is anHttpClient(baseis a reserved word so it cannot be a variable name)