I am working on an ASP.NET application and caching some reference data. The code to c开发者_Python百科reate the cache is invoked in the application_start event in global.asax. My problem is that the application_start event is being invoked multiple times which slows the application access. To test the issue I reinstalled the application. The application_start event was fired on first access to the application (as expected) and again in about an hour even though I did not make any changes. I am not making any file system changes in the application's bin file, and the application pool is set to default recycle settings (1740 minutes), so I am not sure why the event is being invoked.
Thanks
I would check the Idle Time-out setting (defaults to 20 minutes). If the site doesn't process any requests for 20 minutes, the worker process will shut down, therefore the next time you run the app thereafter, you will get another App Start event.
You could log reason for restart in Application_End method of Global.asax.cs, I am using this code :
protected void Application_End(object sender, EventArgs e)
{
HttpRuntime runtime = (HttpRuntime)typeof(System.Web.HttpRuntime).InvokeMember("_theRuntime", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField, null, null, null);
string shutDownMessage = "";
if (runtime != null)
{
shutDownMessage = Environment.NewLine + "Shutdown: " +
(string)runtime.GetType().InvokeMember("_shutDownMessage", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, runtime, null) +
Environment.NewLine + "Stack: " + Environment.NewLine +
(string)runtime.GetType().InvokeMember("_shutDownStack", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, runtime, null);
}
}
精彩评论