c# - Async and Await - Will control return immediately from an MVC action method? -


i'm learning how use async , await. have following method sends email:

public async void send() {     // create network credentials object     var credentials = new networkcredential(azureusername, azurepassword);      // create web transport sending email     var transportweb = new web(credentials);      // send email     await transportweb.deliverasync(this._email); } 

this code exist in mvc app i'm creating. user initiate action in browser , call made controller action method , email method called within action method.

my understanding last line executed (the line await), control returns caller, while deliverasync method completes task. assuming correct, let's assume email taking long time send, maybe 30 seconds. controller action method return control browser though deliverasync method still attempting execute send? ideally have happen.

your understanding correct. don't use async void though, there no need. use async task , sure process errors. right never find out bugs causing crashes.

will controller action method return control browser though deliverasync method still attempting execute send?

that depends on method does. it's code not here. right has no way of awaiting send yes.

it important note background work in asp.net can die @ time when worker process exits (deployment, reboot, crash, ...).


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -