What is the behavior of calling an async method without the await and in a non-async method? I'm asking because I see Visual Studio not displaying any warning on the call to the async method as if it were a perfectly normal thing to do. Does the async method behave as if it were synchronous in such case?
The fact that a method has async
as a modifier is an implementation detail of the method. It just means you can write asynchronous code more easily. It doesn't change how the method is called at all.
Typically an async method returns Task
or Task<T>
. It can return void
, but that's usually only used for event handlers, as otherwise the caller can't tell when the method has completed. In C# 7 it can also return a custom task type.
Now how the caller uses that return value is up to them. Suppose a method returns Task<int>
- a synchronous method might call that method then ignore the returned task completely ("fire and forget"), or attach a continuation with ContinueWith
, or pass it to an async method that will await it. None of that changes how the async method itself behaves.
See more on this question at Stackoverflow