我试图通过在退出页面之前发送电子邮件来避免等待时间。
页面/应用程序在退出之前执行一系列操作,如下所示:
- 数据库交互
- 发送电子邮件(向经理更新有关该交易的信息)
- 退出页面/应用程序。
函数背后的代码:
ExecEntryOnTbl(SQL);// <-- update / insert to database
sendMailNote(action);// <-- send mail with notification of update
exitTC(action, custid);<-- exit page.
done via javascript :
window.location.href = "someOtherPage.aspx"
from code behind via
RegisterClientScriptBlock(...)
我想解决这个问题:
在执行以下操作之前,我怎样才能避免等待sendMailNote()
完成exitTC()
。那可能吗 ?
更新电子邮件类/方法
public static class mail { public static string aReciver, bSubject, cBody; public static void sendMailNoteExc() { string SmtpServer = "smtp.gmail.com"; int port = 111; string sender = "aaa@bbb.com"; string ReCiver = aReciver; string Subject = bSubject; string Body = cBody; string account = "acc@domain.com"; 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); } }