There are many cases where the suffix of any asynchronous method with Async is simply redundant. If your method returns Task
or Task<T>
, and its purpose is to obtain data from a database or other network resource, then, of course, it runs asynchronously. The compiler will also almost always give you an error if you forget to wait for something. With this in mind, there are several good reasons for suffixing asynchronous methods using Async
:
- The method runs asynchronously, but does not return
Task
- There is an alternative other method with the same name that runs synchronously
- Forgetting the wait when calling the code is unlikely to be caught by the compiler
The suffix of the method name with Async
means that the method runs asynchronously, which this method does. Whether he uses it with async/await
or directly returns another task - an implementation detail. Imagine you were looking at code that calls a method that forgets to use. Which of these makes the mistake more obvious?
var item1 = _example.Get(itemId1); var item2 = _example.GetAsync(itemId2);
Based on something else, there is no reason to believe that something is wrong with the first line. The second line, at least, will cause some eyebrows.
source share