c# - Asynchronous call from Application_Error() -


i trying figure out how create asynchronous call application_error method in mvc.

i have e-mail dll have written sends out e-mail via asynchronous call using smtp client.

the problem when call sendemail method in dll have conflict of needing await call. if try this:

protected async void application_error() {     var await emailservice.sendemail("hello world"); } 

it not work, method never called.

is there way me make asynchronous call synchronous method? research online hinted @ httpserverutility.transferrequest possibly being answer not figure out how make work request, doesn't make sense me @ moment.

limitation of dll, cannot change it.

i don't know why async call not send email. should. there's bug somewhere.

but workaround is:

task.run(async () => { await emailservice.sendemail("hello world"); }).wait(); 

you simplify , optimize simplest way bring idea across. pattern safe way synchronously call async method. not perf, not matter here because sending email 1000x more expensive overhead.

if want keep async behavior remove wait. although @ point wonder why sending not working in first place. bug triggered async behavior or there?!


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -