DEV Community

Discussion on: Await / Async in .NET

Collapse
 
lincoln profile image
Lincoln Tran

Thank you very much, that's mean , I only call the async function (it will be async) and assign it to variable
var cookTask = CookPotatoes();

Collapse
 
webjose profile image
José Pablo Ramírez Vargas

Not sure I follow. Are you asking a question? I'll try to guess.

With an asynchronous function, you have 2 choices: Await it, or not await it.

If you await it, the executing thread will immediately mark as "do for later" all of the code below the await and will go look for work to do to its task queue.

If you don't await it, the asynchronous task is started, but the executing thread that started it does not wait for it to finish, and continues processing the code. This is the case I explained. Cooking is started but not awaited. The thread continued to grate the cheese while the kitchen cooktop cooked the potatoes.

Either choice is valid as long as it gets you the desired result, ideally in the fastest possible time.