应用程序池自动关闭的解决方法

时间:2021-03-30 20:30:25

while (true)
{
using (ServerManager sm = ServerManager.OpenRemote("localhost"))
{

string poolname ="8080";//端口号

ApplicationPool appPool = sm.ApplicationPools.FirstOrDefault(x => x.Name == poolname);
if (appPool != null)
{
//当前应用程序是关闭状态,立刻开启
if (appPool.State == ObjectState.Stopped)
{
appPool.Start();
}
else if (appPool.State == ObjectState.Unknown)
{
appPool.Recycle();
}

Console.Write("正在监视IIS状态,请勿关闭" + System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+" \r\n");

//10分钟检查一次
System.Threading.Thread.Sleep(10000);

}
}
}