Is it possible to return an ASP page before continuing with server-side operation (e.g. logging)

Is it possible to return the page response to the user before you finish the work of your entire server part?

Those. I have a cheap hosting account without a database, but I would like to register a specific event by calling the web service on another, more expensive hosting account (i.e. a very slow registration operation)

I really don't want the user to have to wait for this slow registration operation to complete before their page is displayed.

Do I need to twist a new thread or make an asynchronous call? Or can I return the page and then continue to work happily in the same thread / code?

Using ASP.Net (webforms) C # .Net 2.0 etc.

+1
source share
2 answers

You probably need a second thread. An easy option would be to use ThreadPool , but in a more complex setup, the producer / consumer queue will work well.

At the simplest level:

  ThreadPool.QueueUserWorkItem(delegate { DoLogging(state details); }); 
+2
source

Are you sure you can try Response.Flush .

Having said that, making an asynchronous call may be the best way to do what you want to do. Response.Flush just flushed the output buffer to the client, an asynchronous call will allow you to disable the log call and not affect the client load time.

Keep in mind that an asynchronous call made during the life cycle of a page in ASP.NET may not return in time for you to do something with the response.

+1
source

All Articles