title: In ASP.Net, How do I run code after sending page
body: <p>In ASP.Net, I want to run some code (logging, other cleanup) after the page has already been sent to the user.  I don't want this code to interfere with the amount of time it takes the client to receive a response.  I tried placing this code in the OnUnload part of the page, but through testing (using breakpoints, or busy waiting loops) the client does not actually display the page until the code in the OnUnload is finished executing.  Even though the response object is no longer available at this point, and therefore I would assume that the buffered response has been sent to the client, the client still does not display the page until the OnUnload is finished executing.  The only way that seems to work at the moment is to start a new thread to do the work, and allow the OnUnload to finish immediately.  However, I don't know if this is safe or not.  Will the server kill the thread if it executes too long after the page is already sent out?  Is there a more correct way to accomplish this?</p>