Last post Jan 13, 2016 08:46 AM by Chris Zhao
Jan 12, 2016 09:12 AM|iLens|LINK
I have an application where each user's interaction with the site takes many pages and lasts up to 10 minutes. It runs 24/7 in its own apppool.
As the user progresses through the pages, I store the data they provide in the session state.
I have disabled automatic recycling to avoid the session state getting destroyed mid-interaction, and I've tried to schedule a recycle at a specific time (4am on Tuesdays) with a timer in the Application.Start event. I've tried many approaches from different
forums - currently HttpRuntime.UnloadAppDomain(). The Application.OnEnd and Application.Start events fire and the code runs, but the "old" version of the app seems to continue running. Eventually the site goes non-responsive.
How can I programatically cause the app to stop and then restart as if the application pool had recycled?
Jan 13, 2016 03:10 AM|TechView|LINK
If you want to set duration in the app pool, this would be recommended and hopefully helpful too:
And to do it programmatically, follow the below links:
Jan 13, 2016 08:46 AM|Chris Zhao|LINK
The following code examples add an application pool named Contoso to IIS 7 server, then set the application pool to daily recycle at 3:00 A.M.
private static void Main()
using (ServerManager serverManager = new ServerManager())
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection applicationPoolsSection = config.GetSection("system.applicationHost/applicationPools");
ConfigurationElementCollection applicationPoolsCollection = applicationPoolsSection.GetCollection();
ConfigurationElement addElement = applicationPoolsCollection.CreateElement("add");
addElement["name"] = @"Contoso";
ConfigurationElement recyclingElement = addElement.GetChildElement("recycling");
ConfigurationElement periodicRestartElement = recyclingElement.GetChildElement("periodicRestart");
ConfigurationElementCollection scheduleCollection = periodicRestartElement.GetCollection("schedule");
ConfigurationElement addElement1 = scheduleCollection.CreateElement("add");
addElement1["value"] = TimeSpan.Parse("03:00:00");
More information, please see