Stefan Schranz
Jun 10, 2021

--

Hey Chatay,

I think the issue you are stuck on is the fact that you think everything runs in one thread. First off — The behaviour very much depends on the platform you’re on, e.g. WPF has a different behaviour than an ASP.Net or Console app.

But, talking from example from a Console App point of view: The thread is basically not restricted anymore after the first await. An async method runs in the starting thread until the first await is hit, and the continuation can then take place on an arbitrary ThreadPool thread.

This means, that the Sleep will take place in another thread and not affect the starting one at all, and this is what enables the described behaviour.

Does that help?

--

--

Stefan Schranz
Stefan Schranz

Written by Stefan Schranz

26 year old full stack software developer from Germany - Enthusiatic about C#, .Net and Cloud — Visit me at https://dotschranz.net/

No responses yet