0

In C#, the async keyword means that the method contains await keywords that call async methods, otherwise it won't be async. And, await keyword can be used only to async methods. So, the question is: how was the first async method created? Can I do this by myself? Or in order to make my method async I must use existing async methods?

RieBi
  • 11
  • 1
  • you're mistaken about a number of concepts. Please read this great article: it might help clarify a few things for you: [Asynchronous programming with async and await](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/) – paulsm4 Jul 24 '21 at 06:25
  • 1
    See duplicates for the long version. Short version is, the thing you can await does _not_ need to be a method marked `async`. It just has to support a mechanism called an "awaiter", with a method called `GetAwaiter()`. By far the most common example of this is the `Task` object. So anything that returns a `Task` object can be awaited, whether or not it's actually marked with `async`. – Peter Duniho Jul 24 '21 at 06:25
  • 2
    Jon Skeet also wrote a fabulous series of articles introducing us to the async/await world, when it first was introduced. You can learn an enormous amount about its underlying implementation details by reading the articles. Start here: https://codeblog.jonskeet.uk/2010/10/29/initial-thoughts-on-c-5-s-async-support/ – Peter Duniho Jul 24 '21 at 06:27
  • @Peter Duniho: you're correct. Thank you for giving the OP a bit of explanation :) I'd also highly recommend the OP read this Microsoft article: https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/ – paulsm4 Jul 24 '21 at 06:27

0 Answers0