We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Jagdish • 5 years ago

Hi AramT,
I am sorry but I am confused here...
In the above article, you wrote: and if you do not include the keyword await, then the method will be treated as a normal or synchronous method.
But as per my believe, when we have to make any asynchronous method (declared as async) synchronous then we call it using 'await'. i.e. if method ABC is declared with async then the call "ABC();" would be asynchronous and "await ABC();" would then act as synchronous. If possible can you please put some light on it?

Yogi • 4 years ago

I think the keyword await inside a method marked as async causes the next statement after the await to not execute until the statement marked with await has been completed. Once completed, the subsequent statements will proceed until it encounters another await, if any. The method marked as async itself can be called with or without await, depending on our intention. If we want the subsequent statements to wait for the completion of async, we should put await in front of the call. Otherwise, we can just all the async method without await keyword and all the subsequent statements will execute right away before the async method finishes its task. Either way it is non blocking. The thread will still be available to process other things, it just would not process the subsequent statements immediately following the await keyword until it encounters the end of the code block.

AramT, this is an excellent article, providing easy-to-understand explanation. And your sample code is awesome. Thank you for the inspiration!

Terrible arcticle... This article does not explain the principles of work.

Anonymous • 4 years ago

This is a great article explaining how async/await in c# 5. His explanation is cleared & as straightforward as you can get. Are you an entry or a junior developer?

BlackMariah • 4 years ago

Very nice read! I do have a question though. since .Wait() is blocking code, how do I proceed with it, when I have a very long operation? Doesn't wait block my main thread then and prevents further execution of code, which would give litle benefit to simply doing stud synchronously?

Anonymous • 1 year ago

consider a situation where you are making SSO request to a third party API, in this situation, the methods below your SSO request method could probably depend on the results of the SSO request and if you don't await for the request of the sso to be fulfilled, the after methods, might not be able to carry out efficiently what you want them to do. but if the methods are independent, then you can omit the await and just continue with the calls.

Nathan Barnard • 4 years ago

Use await in conjunction with Task.Run and put it on the thread pool if it is CPU-bound work and you don't want it to be blocking.

Cipher Coder • 4 years ago

First Time seeing such a detailed article on async await.. Thanks a lot

Anonymous • 4 years ago

Excellent article & examples. Thank you!