IIS:中止处理程序在客户端连接关闭时工作

发布于 2024-08-09 07:58:31 字数 327 浏览 4 评论 0原文

我有一个处理程序在图像下做一些艰苦的工作。 它看起来像http://example.com/webservice.ashx? imageparam1=100&imageparam2=200

对此处理程序的每个请求大约需要 2-3 秒。

如果客户端关闭连接(即关闭页面或发送另一个图像的请求),我需要一种方法来中止图像生成。

有办法做到这一点吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幽蝶幻影 2024-08-16 07:58:31

您必须观察 HttpContext.Response 对象的 IsClientConnected 属性。当变为 false 时,取消图像生成。

我无法提供更多想法,因为这取决于您创建图像的方式。我只能建议创建单独的生成线程,该线程可以从定期检查连接的主线程中中止。此外,必须以某种方式清理生成器的资源,这可能是增加解决方案复杂性的主要问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文