我对旧版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
答案 0 :(得分:4)
您should not use Task.Run
in ASP.NET at all (classic or core)。您也不应该使用Result
阻止异步代码; 可以 cause a deadlock with ASP.NET Classic。
对于async
代码,只需使用普通的async
和await
:
var result = await httpClient.getContentAsync();
var other = await methodAsync(model);