c# - Azure 移动服务 InsertAsync 获取状态

标签 c# azure async-await azure-sql-database azure-mobile-services

我正在插入我的 Azure 移动服务 SQL 数据库,它工作正常,但我想知道是否存在错误,以便我可以更正它。

如何从 InsertAsync 获取状态以查看它是成功还是失败?

public static MobileServiceClient MobileService = new MobileServiceClient(
  "https://YOUR-DOMAIN.azure-mobile.net/",
  "YOUR-KEY"
);

static IMobileServiceTable<Product> productTable = MobileService.GetTable<Product>();

Product product = new Product { 
  name = NPDName.Text,
  description = NPDDescription.Text,
  price = NPDPriceExkl.Text,
  tax = NPDTax.Text,
  stock = NPDStock.Text,
  available = NPDCBAvailable.Checked,
  active = true
};

productTable.InsertAsync(product);

最佳答案

How do i get the status from the InsertAsync to see if it succeed or failed?

InsertAsync返回一个任务。如果你想知道它的状态,你需要await它。如果失败,则会传播异常:

public async Task InsertAsync()
{
    Product product = new Product
    { 
       name = NPDName.Text,
       description = NPDDescription.Text,
       price = NPDPriceExkl.Text,
       tax = NPDTax.Text,
       stock = NPDStock.Text,
       available = NPDCBAvailable.Checked,
       active = true
    };

    await productTable.InsertAsync(product);
}

关于c# - Azure 移动服务 InsertAsync 获取状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30692495/

相关文章:

c# - VS2010 安装项目卡住在 'Select Installation Folder'

Azure 移动服务 - 插入数据 - 提供的数据类型无效

javascript - 如果解决时间超过 5 秒,是否可以拒绝 Promise.allSettled 中的每个 Promise?

c# - async void 方法是否在每次调用时都创建一个新线程?

c# - 使用 HttpWebRequest.GetResponse() 抓取屏幕时出现错误 "The remote server returned an error: (403) Forbidden"

c# - 为 Console.Write 添加前缀的推荐方法是什么?

c# - 寻找计算复杂折扣的模式/最佳实践

Azure 应用程序注册通过 powershell Azure CLI 添加授权的客户端应用程序

git - 从发布 (CD) 管道触发构建 (CI) 管道?

c# - 对如何构造调用 SmtpClient.SendMailAsync() 的异步/等待代码感到困惑