You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I observed a strange behavior in ApmAsyncFactory. If the task contains a path that returns synchronously, then the execution hangs. It's easy to reproduce, so I'll just provide an example. I'll use asmx web service to demonstrate the issue.
publicclassDemoService:System.Web.Services.WebService{[WebMethod]publicIAsyncResultBeginRun(intoption,AsyncCallbackcallback,objectstate){returnApmAsyncFactory.ToBegin<string>(GetResponseAsync(option),callback,state);}[WebMethod]publicstringEndRun(IAsyncResultresult){returnApmAsyncFactory.ToEnd<string>(result);}privateasyncTask<string>GetResponseAsync(intoption){if(option==1){awaitTask.Delay(1000);return"Works";}elseif(option==2){// I tried awaiting a completed task too, just to test it outawaitTask.CompletedTask;return"Hangs";}else{return"Hangs";}}}
To be sure that this is not a generic problem, I tried the solution provided in this article, and it works without issues.
It seems there is a race condition. If there is an asynchronous execution, the ToBegin returns before the callback is invoked. On the other hand, if the task is already completed, the callback is invoked before the ToBegin manages to return a result.
Just to confirm this, I tried adding a small delay before the callback is invoked, and it works properly then.
EDIT: There is no even race condition here. If the task is already completed, CompleteAsync will run synchronously, and a callback always will be invoked before ToBegin returns;
Hi,
I observed a strange behavior in ApmAsyncFactory. If the task contains a path that returns synchronously, then the execution hangs. It's easy to reproduce, so I'll just provide an example. I'll use asmx web service to demonstrate the issue.
To be sure that this is not a generic problem, I tried the solution provided in this article, and it works without issues.
The text was updated successfully, but these errors were encountered: