C# 如何将MS Kestrel Web服务器设置为异步处理请求并在不阻塞的情况下处理多个请求
我正在使用MVC、WebApi和Kestrel Web服务器测试ASP.NET核心Web应用程序C# 如何将MS Kestrel Web服务器设置为异步处理请求并在不阻塞的情况下处理多个请求,c#,asp.net,asp.net-web-api,asp.net-web-api2,kestrel-http-server,C#,Asp.net,Asp.net Web Api,Asp.net Web Api2,Kestrel Http Server,我正在使用MVC、WebApi和Kestrel Web服务器测试ASP.NET核心Web应用程序 var host = new WebHostBuilder() .UseKestrel(opt => opt.ThreadCount = 10) .UseConfiguration(config) .UseContentRoot(path) .UseStartup<Startup>() .Build(); var
var host = new WebHostBuilder()
.UseKestrel(opt => opt.ThreadCount = 10)
.UseConfiguration(config)
.UseContentRoot(path)
.UseStartup<Startup>()
.Build();
var host=new WebHostBuilder()
.UseKestrel(opt=>opt.ThreadCount=10)
.UseConfiguration(配置)
.UseContentRoot(路径)
.UseStartup()
.Build();
由于某些原因,当服务器处理请求时,它不会接受任何新请求。从我所读到的情况来看,情况不应该如此,但我无法找出我做错了什么
以下是我的WebApi控制器代码:
[HttpPost]
[Route("/api/test/{moduleid}")]
public Task<object> Api(string moduleId, [FromBody] JObject data)
{
return Task.Run( () =>
{
return domain.Handle(moduleId, data);
});
}
[HttpPost]
[路由(“/api/test/{moduleid}”)]
公共任务Api(字符串moduleId,[FromBody]作业对象数据)
{
返回任务。运行(()=>
{
返回domain.Handle(moduleId,data);
});
}
代码不是异步的,所以我正在包装一个Task.Run调用。一切正常,但服务器会阻止新请求,直到当前请求完成。Kestrel在设计上是异步的。我使用的客户端一次只能有一个请求(邮递员)。一旦我使用了多个客户,我发现一切都很好