我希望每隔10秒发送4封电子邮件异步并行,此代码
仅发送第一封电子邮件,我希望在发送4封电子邮件之后
将等待10秒,然后再继续发送4封电子邮件
public static void SendEmail(string mail)
{
BackgroundTaskRunner.FireAndForgetTask(async () =>
{
var smtp = new SmtpClient
{
Host = "smtp.gmail.com",
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential("mail", "password"),
Timeout = 20000
};
using (var message = new MailMessage("frommail", mail)
{
Subject = "",
Body = "",
IsBodyHtml = false
})
{
await smtp.SendMailAsync(message);
}
});
}
HostingEnvironment.QueueBackgroundWorkItem(async cancellationToken => { 尝试 { 等待行动(); } catch(例外e) { // TODO:处理异常 } }); } }
{{1}}
{{1}}