Recycling Application Pools in IIS 6.0

Tags: .NET, CodeSnippets

A quick tip for those of us fond of iisreset. Restarting IIS takes quite a while. Sometimes 15-20 seconds, when my w3wp.exe processes are particularly unruly. In many cases, though, a full iisreset is unnecessary. Since IIS 6.0 expanded its process isolation model to include Application Pools, the simplest way is to simply recycle the application pool - takes only a second, and usually does the trick.

We can do this in .NET with very little effort:

using(DirectoryEntry appPool = new DirectoryEntry(string.Format("IIS://{0}/w3svc/apppools/{1}", host, poolname)))
{
   appPool.Invoke(
"Recycle");
}

Or, if we want to use this in automation scripts or post-build events, we can wrap this in a console application (Here, full source code).

Enjoy. 

8 Comments

Comments have been disabled for this content.