在ASP.NET MVC上运行瓶颈

时间:2019-01-30 15:55:54

标签: async-await task

我对旧版ASP.NET同步上下文有疑问,     如果我在ASP.Net MVC应用程序中运行以下方法:

   `Task.Run(async () => await httpClient.getContentAsync()).Result 
    var response= Task.Run(() => methodAsync(model));
    var other = response.Result 
    var response= await  Task.Run(() => methodAsync(model));`

那些电话会产生瓶颈吗?

all this in an mvc application that is not .net core

1 个答案:

答案 0 :(得分:4)

should not use Task.Run in ASP.NET at all (classic or core)。您也不应该使用Result阻止异步代码; 可以 cause a deadlock with ASP.NET Classic

对于async代码,只需使用普通的asyncawait

var result = await httpClient.getContentAsync();
var other = await methodAsync(model);