in the main() method i call some async method. As I understand async method is processing in the new thread which stops when await, and second thread is created in the method towards await?
Or in the first case, first new thread only for await line? And second for its content
That's not a correct explanation of async & tasks. An async method starts its execution synchronously. Then an await doesn't "pause" the thread really. If it's the first await, the execution returns to the method caller with a Task object. Otherwise the thread returns to the thread pool as "available" which means it can immediately pick another (parallel) task (or thread pool work) if any is there, to start executing it. Later, once the "thing" you were awaiting is available, the task manager takes the first available thread from the thread pool and command it to resume the execution of your task at the point it was awaiting.
Обсуждают сегодня