异步操作方法 [英] Async Action Methods

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

问题描述

我是看着ASP.NET MVC 5模板,我已经注意到许多的行动,并标记为异步:

I was looking at ASP.NET MVC 5 templates and I have notice that many of the actions and marked as async:

public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { }

当我应该这样做的一个MVC行动?当它包含了对数据库的访问?

When should I do this on an MVC action? When it contains access to a database?

如果我打电话的动作里面的仓库,我应该也使用任务,使之异步?

If I call a repository inside the action should I also use Task to make it async?

推荐答案

你的问题的核心是:我什么时候应该让我的MVC的行动异步?见<一href=\"http://blogs.msdn.com/b/rickandy/archive/2009/11/14/should-my-database-calls-be-asynchronous.aspx\" rel=\"nofollow\">http://blogs.msdn.com/b/rickandy/archive/2009/11/14/should-my-database-calls-be-asynchronous.aspx该问题的一个很好的讨论。他只谈到了数据库,但他的观点结转。

The core of your questions is: When should I make my MVC actions async? See http://blogs.msdn.com/b/rickandy/archive/2009/11/14/should-my-database-calls-be-asynchronous.aspx for a good discussion of the issue. He talks about the database only, but his points carry over.

从本质上讲,几乎从来没有调用数据库以异步方式。

Essentially, almost never call the database in an async way.

有关使用异步操作,以减少阻塞线程的Web服务器上的一些数据库应用程序的几乎都是一个完整的浪费时间

For database applications using async operations to reduce the number of blocked threads on the web server is almost always a complete waste of time.

不要别人告诉你,如果可以一直使用异步IO被减损。异步是风靡一时的现在。很多不合理的建议的是为S. $ P $垫。

Don't be detracted by people telling you to always use async IO if possible. Async is all the rage right now. Lot's of irrational advice is being spread.

这篇关于异步操作方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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