简体   繁体   中英

Calling SendAysnc in ASP.NET page

I would like to send out some mail as a response to a page hit. I would like the page not to wait for the mail to be sent, hence SendAsync. In testing, it turned out that "<%@ Page Async="true"...%>", eg,

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CallbackHandler.aspx.cs" Inherits="MyWebRole.CallbackHandler" Async="true" %>

was needed. However, I'm still getting a 500 error, even though the SendAsync is called and email is sent. Here's what I was using. In the interim, I have reverted back to "Send" (which works with Async="true")

sc.SendCompleted += ((sender, e) =>
{
    if (e.Error == null)
    {
        newPayment.transmitted = db.GetSQLDate();
        db.SubmitChanges();
    }
    else
    {
        newPayment.exceptions = e.Error.Message + Environment.NewLine + e.Error.StackTrace;
        db.SubmitChanges();
    }
});
sc.SendAsync(mm, null);

What is the right way to stage this?

I would recommend posting it to some kind of a queue and processing the queue in a separate thread of even another service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM