1 public void Emails(string email) { 2 try 3 { 4 AsyncCallback ac = new AsyncCallback(call); 5 6 MailMessage mail = new MailMessage(); 7 mail.From = new MailAddress("jiancixiuxian@gmail.com","aaa",Encoding.UTF8); ; 8 mail.To.Add(email); 9 mail.Subject = "aaaa"; 10 mail.SubjectEncoding = Encoding.UTF8; 11 mail.Body = "aaaa"; 12 mail.IsBodyHtml = true; 13 mail.Priority = MailPriority.High; 14 15 SmtpClient sc = new SmtpClient(); 16 sc.Host = "smtp.gmail.com"; 17 sc.Port = 587; 18 sc.Credentials = new NetworkCredential("jiancixiuxian@gmail.com", 此处密码); 19 sc.DeliveryMethod = SmtpDeliveryMethod.Network; 20 sc.EnableSsl = true; 21 sc.SendCompleted += sc_SendCompleted; 22 sc.SendAsync(mail, null); 23 24 25 } 26 catch (SmtpException c) 27 { 28 29 throw; 30 } 31 32 } 33 34 void sc_SendCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) 35 { 36 37 }
运行就报错了
现在无法开始异步操作。异步操作只能在异步处理程序或模块中开始,或在页生存期中的特定事件过程中开始。如果此异常在执行 Page 时发生,请确保 Page 标记为 <%@ Page Async="true" %>。
求大神们解答
就是在页面上要加一个关键字<%@ Page Async="true" %>
如果你用的rozar的话,你就在后台开个线程来处理即可