在ASP.NET MVC异步控制器 [英] Async controller in ASP.NET MVC

查看:107
本文介绍了在ASP.NET MVC异步控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查了System.Web.Mvc.AsyncController在MVC 4.0,它具有提供向后兼容ASP.NET MVC 3的评论这是否意味着没有在MVC 4的新实现异步控制器?什么是MVC中的正确方法使4.0异步为了控制器把I / O操作的激烈比IIS的请求的线程池?

I checked the System.Web.Mvc.AsyncController in MVC 4.0, it has the comment "Provided for backward compatibility with ASP.NET MVC 3." does this mean there is a new implementation of async controller in MVC 4? what's the correct way in MVC 4.0 enable async a controller in order to put the I/O intense operations in other thread pool other than IIS request thread pool?

推荐答案

从ASP.NET MVC 4开始,你现在可以使用 System.Web.Mvc.Controller 类的基类,并利用TAP(基于任务的异步模式):

Starting from ASP.NET MVC 4, you can now use the System.Web.Mvc.Controller class as the base class and leverage the TAP (Task-based Asynchronous Pattern):

public async Task<ViewResult> Index() { 

     return View(await GetThingsAsync());
}

请注意,您不必使用异步伺机而附带关键字C#5.0,但他们做异步编程得多,更容易和更容易维护。

Note that you don't have to use async and await keywords which come with C# 5.0 but they make asynchronous programming much, much easier and more maintainable.

看一看下面的文章:

  • Using Asynchronous Methods in ASP.NET MVC 4
  • My Take on Task-based Asynchronous Programming in C# 5.0 and ASP.NET MVC Web Applications
  • Asynchronous Database Calls With Task-based Asynchronous Programming Model (TAP) in ASP.NET MVC 4

这篇关于在ASP.NET MVC异步控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆