I am trying to make my REST APIs more responsive by using Async or Parallel Async Task approach. Here is my code which is synchronous in nature. I have no idea on how can I make it more responsive by using Async or Parallel TPL.
[HttpGet]
public async Task<string> Get([FromQuery(Name = "number")] long number)
{
This is original Synchronous code -
[HttpGet]
public string Get([FromQuery(Name = "number")] long number)
{
ulong lastItem = (ulong)number;
ulong fact = 1;
for (ulong i = 1; i < lastItem; i++)
{
fact = fact * i;
}
return fact.ToString();
}
I want to make this code faster when using REST API - calls. My plan is to use Task Parallel but I am not sure how can I do so? Once I can do I will check if the performance is improved or not.
return await Task.Run(() => //your synchronous code geos here));Parallel Async Taskyou show no such things. alsoasyncdoesn't make anything faster, its a scalability feature which indirectly could be a performance boost, however for a small site probably not