title: Azure Websites AppDomain many restarts
body: <p>I've a group of asp.net 4.0 Websites runing in <strong>Azure Websites</strong> </p>
  
  <ul>
  <li>Compute mode: Standard</li>
  <li>Location: North Europe </li>
  <li>Capacity autoscale: Off</li>
  <li>Instance size: <strong>Large</strong></li>
  <li>Instance Count: 1</li>
  </ul>
  
  <p>The response time is very slow, the trafic is normal, but my log show many <strong>AppDomain shutdowns (more than 3 in one minute)</strong>. My websites load data in cache during de Application_Start to give a rapid response to all subsequents requests but if the Appdomains restarts every time is impossible to give acceptable response times.</p>
  
  <p>The <strong>ShutdownReason</strong> values are many:</p>
  
  <ul>
  <li>ConfigurationChange </li>
  <li>HostingEnvironment</li>
  <li>CodeDirChangeOrDirectoryRename</li>
  <li>BinDirChangeOrDirectoryRename</li>
  <li>BrowsersDirChangeOrDirectoryRename</li>
  </ul>
  
  <p>This have no sense because I've not changed any file in these folders.</p>
  
  <p>I've tested one of these sites in a free mode running very fast and without any unexpected AppDomain restart.</p>
  
  <p>Thanks.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I've included this code in the Application_Start, no file changes have been detected and the AppDomain is restarting again, and again...</p>
  
  <pre class="lang-cs prettyprint-override"><code>var monitorPath = HostingEnvironment.MapPath("~/");
  Application.Add("watcher", new FileSystemWatcher(monitorPath));
  fsw = (FileSystemWatcher) Application["watcher"];
  fsw.EnableRaisingEvents = true;
  fsw.IncludeSubdirectories = true;
  fsw.Changed += fsw_Changed;
  fsw.Created += fsw_Created;
  fsw.Deleted += fsw_Deleted;
  fsw.Renamed += fsw_Renamed;
  </code></pre>
  
  <p><strong>Update 07/15/2013:</strong></p>
  
  <p>using the code from the ScottGu article <a href="http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx" rel="nofollow">http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx</a></p>
  
  <p>I have logged this:</p>
  
  <pre><code>_shutDownMessage=Directory rename change notification for 'C:\DWASFiles\Sites\my-sitename\VirtualDirectory0\site\wwwroot'.
  File Change Notification Error in wwwroot
  HostingEnvironment initiated shutdown
  Change Notification for critical directories.
  File Change Notification Error in App_GlobalResources
  Change Notification for critical directories.
  File Change Notification Error in bin
  Change Notification for critical directories.
  File Change Notification Error in App_Browsers
  Change Notification for critical directories.
  File Change Notification Error in App_Code
  Change Notification for critical directories.
  File Change Notification Error in App_WebReferences
  CONFIG change
  CONFIG change
  CONFIG change
  CONFIG change
  CONFIG change
  CONFIG change
  CONFIG change
  CONFIG change
  CONFIG change
  CONFIG change
  File Change Notification Error in C:\DWASFiles\Sites\my-sitename\VirtualDirectory0\site\wwwroot
  CONFIG change
  File Change Notification Error in 
  HostingEnvironment caused shutdown
  File Change Notification Error in 
  Change Notification for critical directories.
  File Change Notification Error in App_LocalResources
  Change Notification for critical directories.
  File Change Notification Error in App_LocalResources
  CONFIG change
  
  _shutDownStack=   at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
     at System.Environment.get_StackTrace()
     at System.Web.Hosting.HostingEnvironment.InitiateShutdownInternal()
     at System.Web.Hosting.HostingEnvironment.InitiateShutdownWithoutDemand()
     at System.Web.HttpRuntime.ShutdownAppDomain(String stackTrace)
     at System.Web.HttpRuntime.OnCriticalDirectoryChange(Object sender, FileChangeEvent e)
     at System.Web.FileChangesMonitor.OnSubdirChange(Object sender, FileChangeEvent e)
     at System.Web.DirectoryMonitor.FireNotifications()
     at System.Web.Util.WorkItem.CallCallbackWithAssert(WorkItemCallback callback)
     at System.Web.Util.WorkItem.OnQueueUserWorkItemCompletion(Object state)
     at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
     at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
     at System.Threading.ThreadPoolWorkQueue.Dispatch()
     at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
  </code></pre>
  
  <p><strong>Update 07/19/2013:</strong></p>
  
  <p>The metric <strong>Data-In</strong> is very high and has no relation with the requests metric, but when I configure the setting fcnMode=”Disabled” the data-In immediately down to normal values accord with the traffic.</p>