Question

I have a handler that do some hard work under images. It's look like http://example.com/webservice.ashx?imageparam1=100&imageparam2=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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top