在网页线程中运行 [英] Thread Running in Web Page

查看:104
本文介绍了在网页线程中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我浏览到一个asp.net网页,在页面加载下面,多久线程继续为运行后,我关闭浏览器?我会认为它只是在完成自己的,但我不知道,如果会话结束时,或类似的东西,它会终止。

If I browse to an asp.net web page that has the following in the page load, how long will the thread continue to run for after I close the browser? I would assume it would just finish on its own, but I'm not sure if it will terminate when the session ends, or something like that.

protected void Page_Load(object sender, EventArgs e) {
    Thread T = new Thread(new ThreadStart(longRunningMethod));
    T.Start();
}

感谢。

推荐答案

在线程中code停止该线程将停止,即每当 longRunningMethod()终止。

The thread would stop when the code in the thread stops, i.e. whenever longRunningMethod() terminates.

这就是为什么它可以是一个危险的想法来启动应用程序服务器中自己启动线程,至少在没有管理他们的生命周期(即为线程提供逻辑一定时间后要关闭,使得释放确保资源,提供一个上限多少工作线程可以同时运行,等等)。

This is why it can be a dangerous idea to start launching threads yourself within an application server, at least without managing their lifecycle (i.e. providing logic for the thread to be shut down after a certain time, making sure resources released, providing an upper bound on how many "worker threads" can run at once, etc.).

如果一个特定的网页,每次访问产生了一个单独的线程正在启​​动的服务器上,与线程可能运行下去,最终够这些访问都将带来应用服务器给它的膝盖。

If each visit to a particular web page resulted in a separate thread being launched on the server, with the thread possibly running forever, eventually enough of those visits are going to bring the app server to it's knees.

这篇关于在网页线程中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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