
using JinherAMPBTPDeploy;
using MicrosoftWebAdministration;
using RedisHelper;
using System;
using SystemCollectionsGeneric;
using SystemConfiguration;
using SystemIO;
using SystemLinq;
using SystemText;
using SystemThreading;
using SystemThreadingTasks;
namespace Redis
{
public class Program
{
static readonly string AppPoolName = ConfigurationManagerAppSettings["ApplicationPoolName"]ToString();
static readonly string WebSiteName = ConfigurationManagerAppSettings["WebSiteName"]ToString();
static readonly int SleepTime = intParse(ConfigurationManagerAppSettings["SleepTime"]ToString());
static ServerManager sm;
static void Main(string[] args)
{
ConsoleWriteLine($"检测程序启动,{WebSiteName}当网站或其应用池停下后,会自动启动。");
sm = new ServerManager();
new Thread(RecoveryWebSite)Start();
}
static void RecoveryWebSite()
{
while (true)
{
try
{
var pool = smApplicationPools[AppPoolName];
if (pool != null && poolState == ObjectStateStopped)
{
ConsoleWriteLine("检测到应用池" + AppPoolName + "停止服务");
ConsoleWriteLine("正在启动应用池" + AppPoolName);
if (poolStart() == ObjectStateStarted)
{
ConsoleWriteLine("成功启动应用池" + AppPoolName);
}
else
{
ConsoleWriteLine("启动应用池" + AppPoolName + "失败 " + SleepTime / 60 + "秒后重试启动");
}
}
var site = smSites[WebSiteName];
if (site != null && siteState == ObjectStateStopped)
{
ConsoleWriteLine("检测到网站" + WebSiteName + "停止服务");
ConsoleWriteLine("正在启动网站" + WebSiteName);
if (siteStart() == ObjectStateStarted)
{
ConsoleWriteLine("成功启动网站" + WebSiteName);
}
else
{
ConsoleWriteLine("启动网站" + WebSiteName + "失败 " + SleepTime / 60 + "秒后重试启动");
}
}
}
catch (Exception ex)
{
ConsoleWriteLine(exMessageToString());
}
GCCollect();
ThreadSleep(SleepTime);
}
}
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)