How do you force the IIS Application Pool to restart whenever the App Domain is reloaded?

A more brutal approach is to call Process.GetCurrentProcess().Kill() Not very graceful, but if your site has its own app pool and you don't care any current requests being brutally stopped, that's quite effective!


Based on your post it appears you know when you want to trigger the restart so here is a Restarting (Recycling) an Application Pool post that will tell you how.


A simplified VB version of the code you shared. This version uses a For loop instead of a LINQ query. Also, in order to use Microsoft.Web.Administration, you must import the DLL from c:\windows\system32\inetsrv

Imports System.Diagnostics
Imports Microsoft.Web.Administration

Dim pid As Integer = Process.GetCurrentProcess().Id
Dim manager = New ServerManager()
For Each p As WorkerProcess In manager.WorkerProcesses
    If p.ProcessId = pid Then
         For Each a As ApplicationPool In manager.ApplicationPools
             If a.Name = p.AppPoolName Then
                 a.Recycle()
                 Exit For
             End If
         Next
         Exit For
    End If
Next