Bil*_*ani 29 c# asp.net email asynchronous
system.net.mail.smtpclient 有两种方法我很困惑.
1.SendAsync(MailMessage,Object)
Sends the specified e-mail message to an SMTP server for delivery. This method does not block the calling thread and allows the caller to pass an object to the method that is invoked when the operation completes. -MSDN
2.SendMailAsync(MAILMESSAGE)
Sends the specified message to an SMTP server for delivery as an asynchronous operation. -MSDN
请注意,两个方法的名称不同,因此它不是重载.这有什么区别?
我正在寻找非常明确的答案,因为MSDN对这两种方法的描述非常模糊(至少对我来说是这样).
Mik*_*oud 29
不同之处在于SendMailAsync使用新async/await技术而另一种使用旧的回调技术.更重要的是Object,传递的内容只是userState在方法完成时传递给事件处理程序.
首先,它们都是异步工作的.
但是,SendAsync自.NET 2以来就存在.为了保持向后兼容性,同时支持新的Tasks系统SendMailAsync.
SendMailAsync如果需要,返回a Task而不是void允许SmtpClient支持new async和await功能.
| 归档时间: |
|
| 查看次数: |
6817 次 |
| 最近记录: |