Monday, May 16, 2005

ASP.NET Application reset behavior

In the March 2005 asp.netPRO magazine, there is an article by Dino Esposito discussing accessing compile-time code programmatically. He explains how code files are generated from the parsed markup files and then get compiled into temporary assemblies in the ASP.NET temp folder(s). Although he makes a very brief mention of how to actually access this code programmatically, he mostly writes about how ASP.NET works under the hood. Towards the end of the article he notes something that I found very interesting. He writes:
"Each ASP.NET application is allowed a maximum number of page recompiles (with 15 as the default) before the whole application is restarted. ...If the lates compilation exceeds the threshold, the AppDomain is unloaded and the application is restarted. Bear in mind that the atomic unit of code you can unlad in the CLR is the AppDomain, not the assembly. Put another way, you can't unload a single assembly without unloading the whole AppDomain."

I develop with the "attach when you need to" versus the "hit play/F5 and lauch I.E. every time" technique. I find this to be much more productive and saves the hastle of having to truly restart my application every time. Granted, this introduces some problems because I'm not starting clean every single time but I find that the occassional inconvenience is far outweighed by the time savings of avoiding a the full recompile-load IE-attach sequence.

When I make file changes that do not require recompiling I go thru many change-save-refresh cycles. I have noticed that most of the time after I refresh there is only a slight delay (sometimes hardly noticable) on the first refresh after a change. I knew that ASP.NET is refreshing its cache of my page but beyond that I was not aware of what was actually going on. Occasionally, the application will seem to hang up, but then return and behave as if I had restarted completely (I'll end up at the login page if I'm in a authenticated application). Based on Esposito's explanation I now understand that I've reached that recompile threshold and my entire application has been restarted. This explains the behavior I've experienced and wondered about.

No comments: