I have a Web API controller. It calls a method that returns an IAsyncResult. When I call the controller, I get the error
An asynchronous module or handler completed while an asynchronous operation was still pending.
How do I get the controller to wait for the asyncresult?
I was planning to use await, but I may just not have figured out the syntax for this use case.
I haven't found an existing answer on SO.
I'm using c# 4.5
[HttpGet]
[Route("GetGridDataAsync")]
public string GetGridDataAsync()
{
var proxy = new Proxy();
return proxy.BeginGetDataAsync("test", ar => proxy.EndGetDataAsync(ar));
}
public IAsyncResult BeginGetDataAsync(string r, AsyncCallback callback){}
public DataResponse[] EndGetDataAsync(IAsyncResult asyncResult){}
You can make your method an async
Task<string>
, create aTask
based on theAsync
methods in theProxy
class andawait
thatExample: