【发布时间】:2013-11-23 23:38:41
【问题描述】:
所以,我有这个 Web API 动作,它执行一个异步函数。
public void Post([FromBody]InsertRequest request)
{
InsertPostCommand.Execute(request);
DoAsync();
}
private async void DoAsync()
{
await Task.Run(() =>
{
//do async stuff here
});
}
我实际上希望控制器操作在异步操作执行时返回到客户端。
我这样做了,因此我得到了一个例外:
System.InvalidOperationException: An asynchronous module or handler completed while an asynchronous operation was still pending.
请问我怎样才能做到这一点??
谢谢
【问题讨论】:
-
一个好问题。但请仔细阅读提供的所有答案。多线程在 ASP.NET 中很棘手。
标签: c# asp.net asynchronous asp.net-web-api