c# - 使用 C# 异步、等待在 Azure 上通过 SendGrid 发送电子邮件

标签 c# azure async-await sendgrid

我正在关注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/

相关文章:

python - 使用 asyncio.wait_for 和 asyncio.Semaphore 时如何正确捕获 concurrent.futures._base.TimeoutError ?

c# - 使用来自两个不同表的两个 SELECT 语句

c# - 让类将自身作为参数传递给泛型基类是邪恶的吗?

azure - 应用程序和用户的 AAD AppRoles allowedMemberTypes

Azure 混合 worker Docker

c# - 其中一个实现需要异步的接口(interface)

c# - 如何在 MSChart 中设置线条颜色?

c# - 游戏图像资源不适合窗口大小

c# - 事件网格客户端 : should it be disposed?

javascript - 为什么 'await'不等待?