0
Use async
in Web API when performing I/O operations. it improves performance, scalability, and responsiveness under load.
Q-1 Ans:
if your controller interacts with databases (like EF Core), external APIs, or file systems. Even though JavaScript can call your API asynchronously, using async
on the server frees up threads during I/O operations, allowing more requests to be handled efficiently.
Q-2 Ans:
- High-traffic Web APIs: Handles more users without blocking threads.
- Long-running I/O tasks: like DB queries, API calls, or file access — improves responsiveness.
- Cloud/hosted apps (e.g., Azure App Service): Scales better under load with fewer resources.
- Apps with many concurrent operations:
async
prevents thread pool exhaustion and improves performance.
Good Luck!
Accepted 0
[HttpGet]
public async Task<ActionResult<IEnumerable<Dsp>>> GetDsp()
{
return await _context.Dsp.ToListAsync();
}
thank u , is there any central configuration for a solution or project?
or i have to use as i have pased in above code.
0
in my case i have called a method of controller from javacript and method returns one table. so kindly explain this senario how i am getting benefited by async method raher than sync method of the controller ?