如何关闭浏览器关闭事件上的所有线程? [英] How to close all threads on Browser close event?

查看:39
本文介绍了如何关闭浏览器关闭事件上的所有线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有运行多个线程的网站.当用户关闭浏览器但线程仍在运行时.如何在浏览器关闭时杀死/停止asp.net中的所有线程.

I have website which runs multiple threads. When user close the browser but threads are still running. How to kill/stop all thread in asp.net on browser close.

推荐答案

当浏览器关闭时,没有消息发送到服务器,因此没有要监听的抢占事件.您要做的是使变量可用于您的线程,该变量指示用户上次从服务器请求资源的时间.自从用户上次请求过期以来经过了一定的时间后,您就结束了线程.然后,在您的HTML中添加一个javascript ajax请求,该请求ping您的服务器以使线程保持活动状态.

There is no message sent to the server when the browser closes so there's no preemptive event to listen to. What you'll want to do is make a variable available to your threads that indicates when the user last requested a resource from your server. Once a certain amount of time has passed since the user last requested expires you end the threads. Then, in your HTML add a javascript ajax request that pings your server to keep the threads alive.

显然,您需要调整超时时间,以平衡用户的性能和可靠性.

Obviously you'll need to tweak the timeouts to balance performance and reliability for your users.

这篇关于如何关闭浏览器关闭事件上的所有线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆