c# - Working of await in Async await -


consider asynchronous (*async / async) function called twice, 1 time await , other without it.

if use await, wait until asynchronous function executed , execute next line?

await db.savechangesasync(); //some code here 

and, if don't use await, continue executing code below without waiting asynchronous function complete?

db.savechangesasync(); //some code here 

am, right on here or await mandatory when comes async functions?

if use await, wait till async function executed , execute next line.

that depends on method returns. returns task[<t>], represents future value. if task completed, keeps running synchronously. otherwise, remaining portion of current method added continuation - delegate callback invoked when asynchronous portion reports completion.

what not do, in either case, block calling thread while asynchronous part continues.

and, if don't use await, continue executing code below without waiting async function complete.

yes

...or await mandatory when comes async functions?

when invoking them? not mandatory, make things convenient. usually, such functions return task[<t>], can consumed via different code. use .continuewith(...), .wait, .result, etc. or ignore task completely. last bad idea, because exceptions on asynchronous functions need go somewhere: bad things happen if exceptions not observed.

when writing them, however: if write async method , don't have await keyword in there, compiler present warning indicating you're doing wrong. again, not strictly mandatory, highly recommended.


Comments

Popular posts from this blog

jQuery Mobile app not scrolling in Firefox -

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -