c# - Web Api 方法返回任务的缺点

标签 c# asp.net asp.net-web-api task taskfactory

为什么返回一个Task<T>的做法来自 Web Api 方法不是默认方法,而是在您在 Visual Studio 中创建新的 Web Api Controller 时获得的方法中?

这样做有什么缺点吗?

public class MyController : ApiController
{
    public Task<string> Boo()
    {
        return Task.Factory.StartNew(() =>
        {
            return "Boo";
        });
    }
}

最佳答案

Are there any disadvantages to doing this?

是的,您无缘无故地降低了代码的可读性、更长的时间和性能。我看不到这样做有任何优势

关于c# - Web Api 方法返回任务的缺点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25663711/

相关文章:

c# - 如何确保文件从我的工作目录复制到 bin/Debug rsp。垃圾桶/释放?

c# - 控制台应用程序中的 HttpContext

c# - 如何在生产中部署 Owin 自托管应用程序?

c# - 无法在 Aspx 页面中从 Codebehind 运行 Javascript 代码

asp.net-web-api - application/x-www-form-urlencoded 的自定义属性名称绑定(bind)

c# - 如何加载列表框中的所有项目而不仅仅是视觉项目

c# - 如何确定哪个用户控件正在调用命令

c# - 我怎样才能使这段代码更优化

c# - 从 WebApi 返回 JsonResult 不工作 ASP.NET

unit-testing - Autofixture 和 WebApi Controller