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

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);

}
}
}

posted @ 2018-08-15 10:00  会飞的小鲸鱼  阅读(909)  评论(0编辑  收藏  举报