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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -