<p>I am trying to figure out what exactly is Appdomain recycling?
When a aspx page is requested for the first time from a DotNet application, i understand that an appdomain for that app is created, and required assemblies are loaded into that appdomain, and the request will be served. 
Now, if the web.config file or the contents of the bin folder, etc are modified, the appdomain will be "recycled".
My question is, at the end of the recycling process, will the appdomain be loaded with assemblies and ready to serve the next request? or a page has to be requested to trigger the assemblies to load?.</p>

[{'answer_id': 37580, 'author': 'MartinHN', 'author_id': 2972, 'author_profile': 'https://Stackoverflow.com/users/2972', 'pm_score': 3, 'selected': False, 'text': '<p>Take a look at this - that might explain it: </p>\n\n<p><a href="http://weblogs.asp.net/owscott/archive/2006/02/21/ASP.NET-v2.0-_2D00_-AppDomain-recycles_2C00_-more-common-than-before.aspx#440333" rel="noreferrer">http://weblogs.asp.net/owscott/archive/2006/02/21/ASP.NET-v2.0-<em>2D00</em>-AppDomain-recycles_2C00_-more-common-than-before.aspx#440333</a></p>\n\n<p>In general. What is called "first hit" on an ASP.NET Website is usually taking longer time, due to compilation, and creation of an AppDomain.</p>\n\n<p>Whenever you deploy a site - make sure to use the "Publish Website" function in Visual Studio, to pre-compile your website. Then the "first hit" penalty is reduced. And remember to set the configuration to Release, and not Debug!</p>\n'}, {'answer_id': 38407, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>If your pages are "updatable," they must be compiled before use.  That means, yes, on first request the assemblies are loaded, compiled, and made ready for accessing.  Whenever these files are changed (even some virus software can trigger this by changing the modified date of the files!), the appdomain gets recycled.</p>\n\n<p>You can configure your web application to not be updatable.  Everything gets compiled into DLLs, and you won\'t see any .ASPX or .CS files in the virtual directory.  It makes your code harder to update (need to put some additional text on your webpage?  Recompile time!), but it increases the availability of your web app.  </p>\n\n<p>However, this still won\'t prevent your web app from being recycled if any of the files are altered.  For example, if you edit web.config, your appdomain will recycle even if its compiled.</p>\n'}, {'answer_id': 39725, 'author': 'Cory Foy', 'author_id': 4083, 'author_profile': 'https://Stackoverflow.com/users/4083', 'pm_score': 2, 'selected': False, 'text': "<p>Recycle shuts down the process hosting the appdomain. You'll notice that the PID changes when you recycle it.</p>\n\n<p>Unloading the AppDomin simply unloads all of the assemblies in the AppDomain, which can then be reused.</p>\n\n<p>The important thing to remember is that once the CLR is loaded into a process, it can't be removed. So if you needed to do something as soon as the CLR is loaded, then simply unloading the AppDomain won't help, because the CLR won't be reloaded. </p>\n\n<p>Also not that IIS isn't the only process which can host the AppDomain - any process can, and you don't always want to kill the whole process just to unload your assemblies.</p>\n"}, {'answer_id': 5651141, 'author': 'Marcos Silvestri', 'author_id': 706263, 'author_profile': 'https://Stackoverflow.com/users/706263', 'pm_score': 7, 'selected': True, 'text': '<p>Well, I think the thread was getting smoothly to a final conclusion, but in the end, it was otherwise.</p>\n\n<p>I\'ll try to answer the question based on my understanding and leveraging what i\'ve just read about in other web sites.</p>\n\n<p>First of all, I myself try to avoid the term recycle other than for Application Pools since this may render someone confused. Now, getting to process, pools and AppDomain, I see the picture as follows:</p>\n\n<p>An Application Pool is, in short, a region of memory that is maintained up and running by a process called W3WP.exe, aka Worker Process. Recycling an Application Pool means bringing that process down, eliminating it from memory and then originating a brand new Worker Process, with a newly assigned process ID.</p>\n\n<p>Regarding Application Domains, I see it as subsets of memory regions, within the aforementioned region that plays the role of a container. In other words, the process in memory, W3WP.exe in this case, is a macro memory region for applications that stores subset regions, called Application Domains. Having said that, one process in memory may store different Application Domains, one for each application that is assigned to run within a given Application Pool.</p>\n\n<p>When it comes to recycling, as I initially told, it\'s something that I myself reserve only for Application Pools. For AppDomains, I prefer using the term \'restart\', in order to avoid misconception. Based on this, restarting a AppDomain means starting over a given application with the newly added settings, such as refreshing the existing configuration. That happens within the boundaries of that sub-region of memory, called AppDomain, that ultimately lies within the process associated with a respective Application Pool. Those new settings may come from files such as </p>\n\n<p>web.config,\nmachine.config,\nglobal.asax,\nBin directory,\nApp_Code,</p>\n\n<p>and there may be others.</p>\n\n<p>AppDomain are isolated from each other, that makes total sense. If not so, if changes to a web.config, let\'s say, of application 1, requited recycle of the pool, all other applications assigned to that pool would get restarted, what was definitely not desired by Microsoft and by anyone else.</p>\n\n<p>Summarizing my point, </p>\n\n<ul>\n<li>Process (W3WP.exe)\n\n<ul>\n<li>AppDomain 1</li>\n<li>AppDomain 2</li>\n<li>AppDomain 3</li>\n<li>AppDomain n</li>\n</ul></li>\n</ul>\n\n<p>n = the number of assigned applications to the Application Pool managed by the given W3WP.exe</p>\n\n<ul>\n<li>Processes are memory regions isolated from one another</li>\n<li>AppDomains are sub-memory regions isolated from one another, within the same process</li>\n<li>Global IIS settings changes may require Application Pool recycle (killing and starting a new Worker Process, W3WP.exe)</li>\n<li>Application-wide settings changes AppDomains concerns, and they may get restarted after changes in some specific files such as the ones outline above</li>\n</ul>\n\n<p>For further information, I recommend:</p>\n\n<p><a href="http://blogs.msdn.com/b/david.wang/archive/2006/03/12/thoughts-on-iis-configuration-changes-and-when-it-takes-effect.aspx" rel="noreferrer">http://blogs.msdn.com/b/david.wang/archive/2006/03/12/thoughts-on-iis-configuration-changes-and-when-it-takes-effect.aspx</a></p>\n\n<p><a href="https://stackoverflow.com/questions/302110/what-causes-an-application-pool-in-iis-to-recycle">What causes an application pool in IIS to recycle?</a></p>\n\n<p><a href="http://blogs.msdn.com/b/tess/archive/2006/08/02/asp-net-case-study-lost-session-variables-and-appdomain-recycles.aspx" rel="noreferrer">http://blogs.msdn.com/b/tess/archive/2006/08/02/asp-net-case-study-lost-session-variables-and-appdomain-recycles.aspx</a></p>\n\n<p>Regards from Brazil!</p>\n'}]
['https://Stackoverflow.com/questions/37564', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1647/']