Last post Oct 18, 2018 01:49 AM by Nan Yu
Oct 16, 2018 06:41 PM|jwang_ga|LINK
I am working on a project that integrates two applications via REST/JOSN API. In general, App A will send a request to Application B. App B will process the request and send the result back. If for a task that will take more than a
few milliseconds for App B to process, then App B is required to send a response immediately to App A acknowledging the request is received. And it then will send the result back to App A via a POST API call to App A once the task is completed.
I am wondering how this can be done in App B. I tried using Event-Based Asynchronous Patten. It does not work as it throws an exception of "An asynchronous module or handler completed
while an asynchronous operation was still pending."
Any suggestions or help will be greatly appreciated.
Oct 16, 2018 07:14 PM|mgebhard|LINK
Assuming that App B is a web application, fire up a background task to finish whatever processing is required and return a response to the caller; App A. Invoke the POST to App A once the process on App B competes.
Oct 17, 2018 04:40 AM|jwang_ga|LINK
Thanks for your response. Would you please elaborate how to fire up a background task in the ApiController-based controller? Any sample code that you can point me to? As I mentioned, I tried to fire off a separate thread using Event-Based Asynchronous Patten,
but it appears that the controller needs to wait for the completion of asynchronous process before it can return a response.
Oct 17, 2018 09:51 PM|jwang_ga|LINK
I found a new API in .NET Framework 4.5.2 or higher, that is, the
HostingEnvironment.QueueBackgroundWorkItem Method, which apparently provides the functionality I am looking for.
Oct 18, 2018 01:49 AM|Nan Yu|LINK
Hi jwang_ga ,
QueueBackgroundWorkItem is added from .NET 4.5.2 , and you can also find other solutions which provide background task feature such as QUARTZ.NET , FluentScheduler :