Recycling Application Pools in IIS 6.0
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.
Plip said
Cool, I'm quite fond of "End Task" ;-)
Todd Bleeker said
I just use the following short cut to reset my SharePoint Application Pool in IIS6:
C:\WINDOWS\system32\cscript.exe C:\WINDOWS\system32\iisapp.vbs /a MSSharePointPortalAppPool /r
<Todd />
Todd Bleeker said
I forgot to mention, this trick requires Win2K3 SP1.
<Todd />
csegura said
Thanks, thanks, thanks
carlos.
espinete said
Hi mister, if I want restart AppPool ?? Thanks in advance.
Milo said
Hi there We have a Web farm with 3 servers that point to central file repository. In the last couple of months, we have this problem where the sites hang(when trying to authenticate users) and then timeout. Now recycling the app does the trick. 2 questions: a)Is there a way to determine when the application pool needs to be recycled and then proceed to recycle? b)Has anyone experienced the same problem? Thanks in advance.
weblogs.asp.net said
427075.. Great idea :)
Taur said
This link is brokend