IIS: Abort handler work on client connection close
I have a handler that do some hard work under images. It's look like http://example.com/webservice.ashx?imageparam1=100&imag开发者_运维技巧eparam2=200
Each request to this handler take about 2-3 seconds.
I need a way to abort image generation if client close connection(i.e. close page or send request for another image).
Is there is a way to do this?
You have to watch IsClientConnected
property of HttpContext.Response
object. When it changes to false, cancel image generation.
I can't provide more ideas as it depends on the way you create image. I can only advice to make separate generation thread that can be aborted from main thread that periodically checks connection. Also generator's resources have to be cleaned up somehow and that can be major issue increasing solution complexity.
精彩评论