Trying to avoid the delay caused by sending an email before exiting the page.
The application is performing a series of actions before exiting:
- Database interaction
- Sending Email (notifying a manager about the transaction)
- Exiting the page/application.
Code behind function:
ExecEntryOnTbl(SQL);// <-- update / insert to database
sendMailNote(action);// <-- send mail with notification of update
exitTC(action, custid);<-- exit page.
Done through Javascript:
window.location.href = "someOtherPage.aspx"
from code behind via
RegisterClientScriptBlock(...)
Looking for a way to address the issue:
How can I proceed to exitTC()
without waiting for sendMailNote()
to finish its task? Is it feasible?
Update the email class/method
public static class mail { public static string aReciver, bSubject, cBody; public static void sendMailNoteExc() { string SmtpServer = "smtp.gmail.com"; int port = 111; string sender = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c2a3a3a382a0a0a0eca1adaf">[email protected]</a>"; string ReCiver = aReciver; string Subject = bSubject; string Body = cBody; string account = "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3b5a58587b5f54565a5154585456">[email protected]</a>"; string Pass = "a123456"; Send(SmtpServer, port, account, Pass, sender, ReCiver, Subject, Body); } public static void Send(string smtpServer,int Port,string Account, string PassWord, string From, string To, string Subject, string Body) { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient(smtpServer); mail.From = new MailAddress(From); mail.To.Add(To); mail.Subject = Subject; mail.Body = Body; SmtpServer.Port = Port; SmtpServer.Credentials = new System.Net.NetworkCredential(Account, PassWord); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); } }