Yes, when using async I / O, all methods from that point to the controller must return a Task
or Task<T>
. It is custom to say "async all the way", which is code for "do not mix async code with blocking code".
They do not necessarily need the keyword async
, just to return a task.
The execution of the action will look something like this:
- The request arrives and the controller is invoked
- The various layers of the service are invoked until the point where the email is sent using async I / O
- This method returns a task
- All other methods also return a task, including controller action
- The framework puts this task aside, and the thread is free to serve new requests
- When the task completes (ie, when the email is sent), the continuation of the task (all code that comes after
await
) will be executed by a threadpool thread.
See the following Stephen Cleary posts: