如何将ASP.NET MVC的异步Action改写为支持长尾词的异步?

2026-03-30 10:300阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计565个文字,预计阅读时间需要3分钟。

如何将ASP.NET MVC的异步Action改写为支持长尾词的异步?

在未使用异步Action之前,在Action内,可以按如下方式编写:

csharppublic ActionResult Index(){ CustomerHelper cHelper=new CustomerHelper(); ListCustomer result=cHelper.GetCustomerData(); return View(result);}

在没有使用异步Action之前,在Action内,比如有如下的写法:

public ActionResult Index() { CustomerHelper cHelper = new CustomerHelper(); List<Customer> result = cHelper.GetCustomerData(); return View(result); }

以上,假设,GetCustomerData方法是调用第三方的服务,整个过程都是同步的,大致是:

→请求来到Index这个Action
→ASP.NET从线程池中抓取一个线程
→执行GetCustomerData方法调用第三方服务,假设持续8秒钟的时间,执行完毕
→渲染Index视图

在执行执行GetCustomerData方法的时候,由于是同步的,这时候无法再从线程池抓取其它线程,只能等到GetCustomerData方法执行完毕。

这时候,可以改善一下整个过程。

阅读全文
标签:方法

本文共计565个文字,预计阅读时间需要3分钟。

如何将ASP.NET MVC的异步Action改写为支持长尾词的异步?

在未使用异步Action之前,在Action内,可以按如下方式编写:

csharppublic ActionResult Index(){ CustomerHelper cHelper=new CustomerHelper(); ListCustomer result=cHelper.GetCustomerData(); return View(result);}

在没有使用异步Action之前,在Action内,比如有如下的写法:

public ActionResult Index() { CustomerHelper cHelper = new CustomerHelper(); List<Customer> result = cHelper.GetCustomerData(); return View(result); }

以上,假设,GetCustomerData方法是调用第三方的服务,整个过程都是同步的,大致是:

→请求来到Index这个Action
→ASP.NET从线程池中抓取一个线程
→执行GetCustomerData方法调用第三方服务,假设持续8秒钟的时间,执行完毕
→渲染Index视图

在执行执行GetCustomerData方法的时候,由于是同步的,这时候无法再从线程池抓取其它线程,只能等到GetCustomerData方法执行完毕。

这时候,可以改善一下整个过程。

阅读全文
标签:方法