tags:

views:

54

answers:

1

How do I instruct the browser not to expect any more content to be coming down the line? Kinda like the server saying “I got what I need, you don’t need to wait while I finish the processing of the page”.

I have a server-side task, which is initiated when a certain page is hit. The task may be time-consuming, but the rendered HTML will always be the same, i.e. like a “Thank you for starting the task” message.

I’m considering starting a new thread to handle the task, but I believe there must be a more elegant solution, where you just send the right headers/instructions to the browser and then continue processing.

Any ideas?

+2  A: 

This will send your message to the browser:

Response.Flush()

However, I believe the responsibility of notifying the client that the transmission is complete is done by IIS, which it will not do until the ASP.NET engine finishes it's part of the request and passes control back to IIS. Your best bet is to start a new thread, which should not cause any problems since the request thread will end almost immediately after the new one begins... you still only have one thread per request.

Rex M
Absolutely awesome response, thanks!I was aware of the Response.Flush method, but I also had this feeling that it wasn't exactly what I was looking for. Your answer confirms my "gut feeling", and sheds some very valuable light on how ASP.NET and IIS interact. Brilliant. New thread is is... :)
Jakob Gade
See this comment from a related question on SO: http://stackoverflow.com/questions/57845/backgroundworker-thread-in-asp-net/57891#57891 Should I worry about the new thread getting killed?
Jakob Gade
If you expect enough load on the server to push the WP to recycle, and/or if this process is important enough to guarantee completion then you should *definitely* run it from something, ANYTHING else than an ASP.NET application. Windows service, batch job, whatever.
Rex M