gpt4 book ai didi

asp.net - ASP.NET何时会杀死新线程?

转载 作者:行者123 更新时间:2023-12-04 03:59:52 26 4
gpt4 key购买 nike

我已经尝试过在这个主题上进行一些搜索,但是我想获得更多信息。

我正在尝试在ASP.NET应用程序内启动一个新线程,该线程将处理一些需要很长时间的工作。如果我将其放在我的web.config中:

<httpRuntime executionTimeout="5" />

常规请求将在5秒后超时。请记住,这是用于测试。当我从代码中启动新线程时:
    var testThread = new Thread(new ThreadStart(CustomClass.DoStuffThatTakesLongTime));
testThread.Start();

该线程将运行5秒以上,这就是我想要的。但。它将运行多长时间?假设此线程耗时5小时(仅作为示例)。线程何时被杀死?它会一直运行到应用程序池被回收之前吗?还是还有其他东西可以杀死这个线程?

最佳答案

ASP.NET不了解您创建的线程-它会一直运行到AppPool回收或完成为止。

由于ASP.Net不了解此线程,因此,如果服务器认为应回收AppPool,则在任何时候都可能突然中止该线程,这不是一件好事!有关如何订阅“AppDomainIsGoingDown”事件的信息,请参见Phil Haack wrote a blog post

关于可能导致这种情况的原因,我建议阅读blog post by Tess Ferrandez,但简而言之,它们是:

  • It has been scheduled to do so
  • Machine.Config, Web.Config or Global.asax are modified
  • The bin directory or its contents is modified
  • The number of re-compilations (aspx, ascx or asax) exceeds the limit specified by the setting in machine.config or web.config (by default this is set to 15)
  • The physical path of the virtual directory is modified
  • The CAS policy is modified
  • The web service is restarted
  • (2.0 only) Application Sub-Directories are deleted

关于asp.net - ASP.NET何时会杀死新线程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8805173/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com