Using PostRequestHandlerExecute, Flush and Close to clean up after a request - why is this bad?

Posted by Erwin on Stack Overflow See other posts from Stack Overflow or by Erwin
Published on 2010-05-20T22:27:16Z Indexed on 2010/05/20 22:30 UTC
Read the original article Hit count: 536

Filed under:

After some requests I need to clean up after the user - by calling a remote web service to release some resources if I guess the user doesn't need them anymore. It is ok to leave them hanging and letting them time out on the other server, but the polite thing to do is to inform it that I do not need them anymore.

I do not want to waste the users time waiting for cleaning - so I tried to find place to put it. First I tried Application_EndRequest, but I needed something later. Then I found PostRequestHandlerExecute which seemed like a nice place, but I still need a Flush and Close to release the connection to the user.

Protected Sub Application_PostRequestHandlerExecute(ByVal sender As Object, ByVal e As System.EventArgs)
        Response.Flush()
        Response.Close()

        ' Simulation of clean up activity:
        System.Threading.Thread.Sleep(4000) ' Really a couple of web service calls
End Sub

Is there some other place I could put these lengthy clean up routines?

© Stack Overflow or respective owner

Related posts about ASP.NET