I’m currently working with an ASP.NET MVC application that interacts with over 10 suppliers’ APIs to gather data. Our current approach involves waiting for all API calls to complete using Task.WaitAll, but this leads to poor user experience due to connection timeouts. How can we enhance performance in our ASP.NET MVC application to mitigate these timeouts and improve user experience?
I’ve attempted to optimize my ASP.NET MVC application by using Task.WhenAny among other approaches to handle multiple API calls asynchronously. Despite these efforts, I’m encountering persistent errors. The view is displaying no values, and errors seem to be slipping through without being caught. Additionally, the controller is passing these errors to the view. How can I resolve these issues and ensure smoother performance?
So Please let me know if there is a any approach to improve the code.
Example Code below :
for (int i = 0; i < sources.Count(); i++)
{
if (sources[i] == "MY" && suppliers.Contains("MY"))
{
supplier = new SabreRest.Flights();
}
if (sources[i] == "MY" && suppliers.Contains("MY"))
{
supplier = new SabreRest.Flights();
}
if (sources[i] == "MY" && suppliers.Contains("MY"))
{
supplier = new SabreRest.Flights();
}
if (sources[i] == "MY" && suppliers.Contains("MY"))
{
supplier = new SabreRest.Flights();
}
if (sources[i] == "MY" && suppliers.Contains("MY"))
{
supplier = new SabreRest.Flights();
}
if (supplier != null)
{
Task myTask = Task.Factory.StartNew(() =>
{
supplier.Search(copyRequest, flightDetails, newpccMatrixList, client, copiednearbyairports);
});
taskList.Add(myTask);
pccMatrixList.ForEach(a => a.IsAvailable = false);
}
}
Task.WhenAll(taskList);
Sagar P is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.