c# - How to complete request before redirecting -
using c#/asp.net
i have application goes out web service. on return there's couple of things happen:
void cleanup(response response) { // web service takes 30 seconds // method called // send email var email = saleemail.create( response.id datetime.now, "a sale made!"); email.send(); // redirect response.redirect(response.redirecturl, false); context.applicationinstance.completerequest(); }
the idea is, on completion of web service email sent, page redirected.
previously, used normal redirect - result 90% of emails never sent.
i've changed redirect pattern, it's still not perfect - i'm guessing 25% of emails still not coming through.
anyone advise improvements pattern have?
email code:
public static void send(mailmessage message) { guard.argument.notnull(() => message); var c = new smtpclient(); try { c.send(message); } catch (exception ex) { } { c.dispose(); message.dispose(); } }
maybe
try implement async task method sendasync , await await wait how needed send email before jump redirect
//async task public async task cleanup(response response) { using (var smtpclient = new smtpclient()) { await smtpclient.sendasync();...//await } }
Comments
Post a Comment