为什么要创建异步的WebAPI操作,而不是同步的吗?

为什么要创建异步的WebAPI操作,而不是同步的吗?

问题描述:

我在我创建了一个Web API以下操作:

I have the following operation in a Web API I created:

// GET api/

[HttpGet]

[Route("pharmacies/{pharmacyId}/page/{page}/{filter?}")]

public CartTotalsDTO GetProductsWithHistory(Guid pharmacyId, int page, string filter = null ,[FromUri] bool refresh = false)

{

return delegateHelper.GetProductsWithHistory(CustomerContext.Current.GetContactById(pharmacyId), refresh);

}

此WebService的呼叫通过jQuery的Ajax调用这种方式完成的:

The call to this webservice is done through a Jquery Ajax call this way:

$.ajax({

url: "/api/products/pharmacies/<%# Farmacia.PrimaryKeyId.Value.ToString() %>/page/" + vm.currentPage() + "/" + filter,

type: "GET",

dataType: "json",

success: function (result) {

vm.items([]);

var data = result.Products;

vm.totalUnits(result.TotalUnits);

}

});

我已经看到了实现previous操作这样一些开发商:

I've seen some developers that implement the previous operation this way:

// GET api/

[HttpGet]

[Route("pharmacies/{pharmacyId}/page/{page}/{filter?}")]

public async Task GetProductsWithHistory(Guid pharmacyId, int page, string filter = null ,[FromUri] bool refresh = false)

{

return await Task.Factory.StartNew(() => delegateHelper.GetProductsWithHistory(CustomerContext.Current.GetContactById(pharmacyId), refresh));

}

不得不说,虽然,GetProductsWithHistory()是一个相当长的操作。鉴于我的问题和情况,将如何使的WebAPI操作异步有什么好处?

Gotta say, though, that GetProductsWithHistory() is a quite long operation. Given my problem and context, how will making the webAPI operation asynchronous benefit me?

相关推荐

天猫商家中心入口怎么打开?如何查看订单和售后?
365bet足球即时比分网

天猫商家中心入口怎么打开?如何查看订单和售后?

📅 07-29 ⭐ 3234
包裹显示签收,但买家声称没收到,怎么破? 情形一 情形二 情形三
斗鱼“贵族”系统正式上线
365bat提现

斗鱼“贵族”系统正式上线

📅 06-28 ⭐ 4678
首頁〉成語檢索〉正文〉[從容不迫]
365bat提现

首頁〉成語檢索〉正文〉[從容不迫]

📅 07-05 ⭐ 4891
html 如何制作抽奖
365bet足球即时比分网

html 如何制作抽奖

📅 07-06 ⭐ 3532
主存储器
365bet足球即时比分网

主存储器

📅 07-15 ⭐ 2215
推荐阅读 ❤️