views:

121

answers:

1

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?

+1  A: 

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.

terR0Q
Hmm. Thanks I will try it.Image generates on the separate WCF service, so there is no problem with resources.
AlfeG
I mean disposing Graphic and all drawing tools. Memory leaks can be the issue if some objects are not cleaned up by GC. And as I know there are unmanaged resources involved when working with images in .NET.
terR0Q