C#C
C#4y ago
palapapa

Understanding await control flow [Answered]

According to my understanding, when the control flow reaches an await, it would return immediately to the call site. But what would happen if the method you are currently awaiting awaits another method?
Let's say I have 3 methods: Main, AsyncMethod1, and AsyncMethod2. If I call AsyncMethod1 in Main, the control flow would immediately return to Main as far as I know. Then, inside AsyncMethod1, it awaits AsyncMethod2. In that case, would the control flow return to AsyncMethod1? But that wouldn't make much sense because AsyncMethod1 is already awaiting something so it cannot continue. Which part of my understanding is wrong?

By the way, if I have an async Main, where would the control flow return to when I await in Main? Does it simply not return?
Was this page helpful?