I am using asp.net web api 2 and Entity Framework 6.
Original pseudo code
public IHttpActionResult GetProductLabel(int productId) { var productDetails = repository.GetProductDetails(productId); var label = labelCalculator.Render(productDetails); return Ok(label); }
Modified code
public async Task<IHttpActionResult> GetProductLabel(int productId) { var productDetails = await repository.GetProductDetailsAsync(productId); // 1 long second as this call goes into sub services var label = labelCalculator.Render(productDetails); // 1.5 seconds synchrounous code return Ok(label); }
Before my change, everything was done synchronously.
After my change, a call to a remote service that calls the database again is asynchronous.
Then I make a synchronization call to a rendering library that offers only synchronization methods. The calculation takes 1.5 seconds.
Is there any other advantage in that the remote database_service service made an asynchronous call, but there was no second call? And is there anything that I could improve?
Note
The reason I'm asking about this is this:
"With asynchronous controllers, when a process waits for I / O to complete, its thread is freed up for use by the server to process other requests.
So, when the first remote database_service call is processed and waits 1 second, the thread returns to IIS ?? !!
But what about calculating the 2nd mark, which is 1.5 seconds, which again blocks the current thread in 1.5 seconds?
So, I release and block the flow, which does not make sense or what do you think?
Pascal
source share