DEV Community

loading...

Discussion on: Asynchronous C#: Cherry on the top 🍒 (Tips and Tricks)

drdamour profile image
chris damour

There are awaits in the nesting, so something is being awaited. Its just the very top level that is fire and forget. Its entirely possible (near impossible of likely) the Thread scheduler schedules the awaited threads exclusively and the program DOESNT exit before all the awaited things (main would just have to be paused for 4 seconds for this to happen). So thats the correction...there is still an await happening..now if there were no awaits anywhere youd be right

Thread Thread
paulafahmy profile image
Paula Fahmy Author

Yes exactly. There IS an await, the execution IS "awaited" in the sense that a context is being captured, etc.
But since the top level caller didn't "use" the await keyword, the execution would start but there would be no guarantee that we'd capture the full expected results.
PourWaterAsync() has indeed started, the inner awaits are functioning as they should, but we did not "wait" for the results and the program continues execution regardless.
I updated this section of the article, I hope I made it clearer this time. Really appreciate the feedback! ♥