Iis6.0 and later versions, view IIS attributes
Http://msdn.microsoft.com/en-us/library/ms525539.aspx
<Iisapplicationpool location = "/lm/w3svc/apppools/defaultapppool"
Apppoolautostart = "true"
Periodicrestartmemory = "2000" // maximum virtual memory MB
Periodicrestartprivatememory = "1000" // maximum memory usage MB
Periodicrestartrequests = "1000" // number of requests
Periodicrestartschedule = "// automatic recovery time
12: 00
20: 00"
>
</Iisapplicationpool>
Code
Protected void startstoprecycleapp (string method)
{
String apppoolname = "defaultapppool ";
Try
{
Directoryentry apppool = new directoryentry ("IIS: // localhost/w3svc/apppools ");
Directoryentry findpool = apppool. Children. Find (apppoolname, "iisapplicationpool ");
Findpool. properties ["periodicrestartmemory"]. value = (object) 512000; // set the maximum virtual memory occupied
Findpool. properties ["periodicrestartprivatememory"]. value = (object) 200000; // you can specify the maximum physical memory usage.
String [] strpamer = {"07:50", "12:00", "20:00 "};
Findpool. properties ["periodicrestartschedule"]. value = (object) strpamer; // set the automatic recycle time
Findpool. commitchanges ();
Apppool. commitchanges ();
Apppool. Close ();
}
Catch (exception ex)
{
MessageBox. Show (ex. Message );
// Lbmsg. Text = string. Format ("Application Program Pool {0} {2} failed: {1} ", apppoolname, Ex. Message, method );
}
}