我正在关注this tutorial使用 SendGrid 从我的 Azure Web 角色发送电子邮件。
这是教程中的相关部分:
// Create credentials, specifying your user name and password.
var credentials = new NetworkCredential("username", "password");
// Create an REST transport for sending email.
var transportREST = REST.GetInstance(credentials);
// Send the email.
transportREST.Deliver(myMessage);
在我看来,transportREST.Deliver 函数是同步的。由于它执行 IO,我更愿意使用新的 .NET 4.5 async,await (我的所有其他代码都是完全异步的)。这可能吗?是否有 SendGrid 的异步 API 或某种方法来包装现有的调用?
最佳答案
目前,SendGrid C# 库没有异步方法,因为我们希望保持与 .NET 4.0 的兼容性。
您可以轻松地自己进行此更改。事实上,here's a commit在我们决定坚持使用 .NET 4.0 后,我恢复了这一点。
更新:自 2013 年 10 月 24 日起和 sendgrid-csharp 1.2.1 起,有一个 DeliverAsync 方法可用
关于c# - 使用 C# 异步、等待在 Azure 上通过 SendGrid 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18363131/