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 t开发者_如何学运维he 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.
THIS DON'T WORK ON MY SERVER ONLY WHEN DEBUGGING IN VISUAL STUDIO 2008!
On the server pages become blank - if i remove the Flush and Close it works, but the user has to wait for the cleanup.
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? Is spawning another thread a better solution?
First of all I think that the architecture you have decided upon sounds like it could need a rework.
To manually close resources gives me a bed feeling.
With that said I would suggest to start a thread to have the cleaning up done asynchronously via a delegate.
精彩评论