0
当我调用web api时,asyn方法启动进程。完成API过程后,asyn进程也停止。这是我的示例代码片段。请为此提供任何解决方案。Asyn进程在API中处理对象时停止API
private readonly ITestService testservice;
public TestController(ITestService test)
{
this.testservice=test;
}
[Route("Sample/SaveMyData")]
[HttpPost]
public IHttpActionResult SaveMyData(MyInfo info)
{
MyInfo inf = new MyInfo();
inf = testservice.SaveMyInformation(info);
SendMailProcess(inf)
return Ok<MyInfo>(inf);
}
private async Task<bool> SendMailProcess(MyInfo emailInfo)
{
await Task.Run(()=> this.testservice.SendMail(emailInfo));
return true;
}
感谢您的回复。如果我想更新数据库中的某些内容,如何在web api中使用异步? –
您有所有数据库访问方法的异步对应项。 E.x,ExecuteNonQueryAsync可用于执行UPDATE。 – Martin
感谢triman。第一个解决了我的问题 –