Continue processing after returning the response to the client

I have a shared handler page (.ashx) that receives an XML document from a leading provider. Then I take this XML document and send it to a third party for underwriting. I wait for a third-party response, then pass that answer on to the lead provider. All this happens after 30 seconds or less.

My problem is that the lead provider will only wait a maximum of 30 seconds before closing the connection and continuing. I am trying to start an internal timer, and if I did not hear from a third-party underwriter, send a response to the lead provider. All of this works great.

What I want to do is send the answer back to the lead provider, but keep waiting for the response from the third-party underwriter. They will deliver it to us ... but sometimes it can take a couple of minutes.

I tried all kinds of combinations

Response.Flush(); Response.Close(); Response.End(); context.ApplicationInstance.CompleteRequest(); 

All I need to do is: a) throw an error about the interruption of the stream or "It is impossible to evaluate the expression because the code is optimized, or your own frame is on top of the call stack"; or b) the client considers that the request was simply terminated and did not receive a response.

I cannot implement a queue-type architecture without processing most of the logic, and even then I do not want to do this because it will increase the response processing time.

Any suggestions? It seems that .Close () and .End () are not intended to work, as I think they are, and I cannot figure out what should be used instead.

+4
source share
1 answer

Maybe System.Threading.ThreadPool.QueueUserWorkitem () can help you?

The idea is to queue an operation that will be executed whenever a thread is free in threadpool.

 public class Data { public int ID {get; set; } public string OtherData { get; set; } } public override void ProcessRequest(HttpContext context) { var workLoad = new Data { ID = int.Parse(context.Request.Params["ID"]), OtherData = context.Request.Params["OtherData"] }; // somewhere before the end : ThreadPool.QueueUserWorkItem(new WaitCallback(LongRunningMethod), workLoad); Response.Flush(); Response.Close(); } public void LongRunningMethod(object state) { var data = (Data)state; CalculateTheOriginOfTheLife(data.ID, data.OtherData); } 
+3
source

All Articles