Does the keyword "async" really make the asynchronous method?

Asked

Viewed 201 times

6

I was seeing a video (at 31:11 minutes) and there says that async does not make the method really asynchronous, it is more a "hint". As it was in English and I am not totally advanced, it was half empty the understanding.

In order to enter the asynchronous world, I did some tests, but with little knowledge and using the debug he won’t act asynchronously I believe.

If the answer is "does not asynchronous", then if it is a hint, what would be the "reason" for this "hint".

  • As important as understanding async, it is also understanding how the await works, as Maniero said, these two commands help a lot and already abstract a lot, however, it is up to you to understand also what is happening behind the commands.

1 answer

7


In fact declare a method as async does not guarantee anything. This is saying to the compiler only that the method can be called asynchronously, ie it can be used with a await. This is the command that will make the asynchronicity. You can call this method synchronously if you wish, although it probably hasn’t been written to use like this.

When we mark the method as async we allow it to contain a await within it.

Currently a method marked with async must return void, Task or Task<T>, ValueTask<T> or anything derived from Task.

You, the programmer, must ensure that the code runs asynchronously, this pair of commands only does the dirty work.

Documentation on the subject. You can translate pages, but knowing how to read in English helps more.

  • Oops... thank you very much, I’m gonna read that documentation right now.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.