ASP.NET HttpApplication的生命周期 [英] ASP.NET HttpApplication lifecycle
问题描述
是否HttpApplication类由Global.asax.cs中扩展应用程序?
的寿命存在目前可以创建的实例哪一点/销毁?
我遇到的Application_Start射击两次,这似乎是什么做的应用程序池回收和发出请求的一部分的方式,虽然这一过程。我不太调试它,我没有此刻的时间深入这么做。因此,相对于上面的问题,是继安全的解决方案?
公共类MvcApplication:System.Web.HttpApplication
{
公共静态对象SYNCLOCK =新的对象();
公共静态布尔applicationBooted; 保护无效的Application_Start()
{
如果(!applicationBooted)
锁定(SYNCLOCK)
如果(!applicationBooted)
{
//这里引导
applicationBooted = TRUE;
}
}
}
如果你在你的日志中看到两次的情况下,检查应用程序池设置为产生一个单一的工作进程。每个工作进程会创建自己的HttpAppication的实例。
Does the HttpApplication class extended by Global.asax.cs exist for the lifetime of the application?
At what point can instances be created/destroyed?
I'm experiencing application_start firing twice, it appears to be something to do with the app pool recycling and making requests part way though this process. I've not quite debugged it and I dont have time at the moment to do so in depth. So, in relation to the above question, is the following a safe solution?
public class MvcApplication : System.Web.HttpApplication
{
public static object syncLock = new object();
public static bool applicationBooted;
protected void Application_Start()
{
if(!applicationBooted)
lock (syncLock)
if(!applicationBooted)
{
// bootstrap here
applicationBooted = true;
}
}
}
If you are seeing the event twice in your logs, check that the application pool is set to spawn a single worker process. Each worker process will create its own instance of the HttpAppication.
这篇关于ASP.NET HttpApplication的生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!