What is Async Await in AspNet 6 (C-Sharp)

Understanding Async Await in AspNet 6

1. After playing with Async Await in Asp.net Application I found that when you use Await on a function, it waits until that function completes executing, I know what you are thinking, this sounds like the exact opposite from what the documentation states? Yes, at least to my experience.

I tested this theory using Microsoft Asp.Net Channels API and try to await for a Channel.WriteAsync() function then move on to Await the Channel.ReadAsync().
What I found was that the Await Channels.WriteAsync() function blocked the Main Thread even when I indicated to the function to run in the background.

e.g. Await Channel.WriteAsync().ConfigureAwait(false);//This function call blocked the UI Thread resulting in no rendering until it finished executing
       Await Channel.ReadAsync().ConfigureAwait(false);//This function call did not execute until the Channel.WriteAsync() completed writing

Best Solution:
I also found out that if you want the UI Thread to go on rendering the UI or Page while the Channel.WriteAsync() and Channel.ReadAsync() executed in the background then prifix you code by:

_= Channel.WriteAsync().ConfigureAwait(false);
_= Channel.ReadAsync().ConfigureAwait(false);
Did you know you could edit this article?

Edit this Article
Async Await .NET 6 published
Was this page helpful?
Yes Yes! this solution to the problem was helpful. No No! this solution to the problem was not helpful.. Leave ErnesTech Feedback.Feedback
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.

Your Session is Ending
Login to Continue

© 2021 - ErnesTech - Privacy