<分区>
假设我们在标准 mvc Controller 中有以下两个方法。
public class SomeController : Controller
{
public async Task<Response> SomeAction1()
=> await _someService.SomeAsyncMethod();
public Task<Response> SomeAction2()
=> _someService.SomeAsyncMethod();
// SomeAsyncMethod might look like this.
// public async Task<Response> SomeAsyncMethod()
// => await someDbAction();
}
简单的问题: Controller 基类是否执行等待/异步任务?
或者这两个 Action 做完全相同的事情吗?
-- 编辑以澄清一点。 --
How Requests Are Processed by the Thread Pool
On the web server, the .NET Framework maintains a pool of threads that are used to service ASP.NET requests. When a request arrives, a thread from the pool is dispatched to process that request. If the request is processed synchronously, the thread that processes the request is busy while the request is being processed, and that thread cannot service another request.
我的目标是了解返回任务的方法是否需要伴随单词 async
。如果关键字不存在,即使 SomeAsyncMethod
中有一个 await
创建回调,它是否会将方法视为同步并保持线程?