LOGO OA教程 ERP教程 模切知识交流 PMS教程 CRM教程 开发文档 其他文档  
 
网站管理员

c#创建并设置应用程序池

admin
2018年9月8日 15:42 本文热度 5373
/// <summary>
/// 创建应用程序池 IIS 7 默认是 FrameWork 4.0  集成模式
/// </summary>
/// <param name="appPoolName"></param>
/// <param name="maxProcesses">最大进程数</param>
/// <param name="queueLength">队列长度</param>
/// <param name="type">0为集成模式1为经理模式</param>
public static bool CreateAppPool7(string appPoolName, long maxProcesses,long queueLength,string type)
{
    try
    {
        ServerManager sm = new ServerManager();
        //判断是否存在应用程序池
        ApplicationPool appPool = sm.ApplicationPools[appPoolName];
        if (appPool == null)
        {
            sm.ApplicationPools.Add(appPoolName);
            ApplicationPool apppool = sm.ApplicationPools[appPoolName];
            if ("0".Equals(type))
            {
                apppool.ManagedPipelineMode = ManagedPipelineMode.Integrated;//托管管道为集成模式  ManagedPipelineMode.Classic为经典模式
            }
            else {
                apppool.ManagedPipelineMode = ManagedPipelineMode.Classic;//托管管道为经典模式  ManagedPipelineMode.Classic为经典模式
            }
         
            apppool.ManagedRuntimeVersion = "v4.0";  //当设置错误时,会在应用程序中创建一个不存在的版本,不会报错
            //应当检测当前电脑是否安装 FrameWork 4.0 ,并处理没有安装时该怎么办
            //apppool.QueueLength
            apppool.Recycling.DisallowOverlappingRotation = false;
            apppool.Recycling.PeriodicRestart.Time = TimeSpan.FromMinutes(0);
            apppool.Recycling.PeriodicRestart.Schedule.Add(TimeSpan.Parse("23:00:00"));
            apppool.Recycling.PeriodicRestart.Schedule.Add(TimeSpan.Parse("06:00:00"));
            apppool.Recycling.PeriodicRestart.Schedule.Add(TimeSpan.Parse("12:30:00"));
            apppool.Recycling.PeriodicRestart.Schedule.Add(TimeSpan.Parse("18:00:00"));
            apppool.Recycling.LogEventOnRecycle = RecyclingLogEventOnRecycle.Memory
                | RecyclingLogEventOnRecycle.Requests
                | RecyclingLogEventOnRecycle.ConfigChange
                | RecyclingLogEventOnRecycle.IsapiUnhealthy
                | RecyclingLogEventOnRecycle.OnDemand
                | RecyclingLogEventOnRecycle.PrivateMemory
                | RecyclingLogEventOnRecycle.Schedule
                | RecyclingLogEventOnRecycle.Time;
            apppool.Recycling.PeriodicRestart.Memory = 40960000;
            apppool.Recycling.PeriodicRestart.PrivateMemory= 0;
            apppool.ProcessModel.IdleTimeout = TimeSpan.FromMinutes(0);
            apppool.ProcessModel.MaxProcesses= maxProcesses;
            apppool.ProcessModel.ShutdownTimeLimit = TimeSpan.FromSeconds(120);//关闭时间限制设置为120秒
            apppool.QueueLength = queueLength;
            apppool.Cpu.Limit = 80000;
            apppool.Cpu.Action=ProcessorAction.KillW3wp;
            apppool.Failure.RapidFailProtection = false;
            apppool.AutoStart = true;
            sm.CommitChanges();
            apppool.Recycle();
          
        }
        else
        {
            //appPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;//托管管道为集成模式  ManagedPipelineMode.Classic为经典模式
            if ("0".Equals(type))
            {
                appPool.ManagedPipelineMode = ManagedPipelineMode.Integrated;//托管管道为集成模式  ManagedPipelineMode.Classic为经典模式
            }
            else
            {
                appPool.ManagedPipelineMode = ManagedPipelineMode.Classic;//托管管道为经典模式  ManagedPipelineMode.Classic为经典模式
            }
            appPool.ManagedRuntimeVersion = "v4.0";  //当设置错误时,会在应用程序中创建一个不存在的版本,不会报错
            //应当检测当前电脑是否安装 FrameWork 4.0 ,并处理没有安装时该怎么办
            appPool.Recycling.DisallowOverlappingRotation = false;
            appPool.Recycling.PeriodicRestart.Time = TimeSpan.FromMinutes(0);
            appPool.Recycling.PeriodicRestart.Schedule.Clear();
            appPool.Recycling.PeriodicRestart.Schedule.Add(TimeSpan.Parse("23:00:00"));
            appPool.Recycling.PeriodicRestart.Schedule.Add(TimeSpan.Parse("06:00:00"));
            appPool.Recycling.PeriodicRestart.Schedule.Add(TimeSpan.Parse("12:30:00"));
            appPool.Recycling.PeriodicRestart.Schedule.Add(TimeSpan.Parse("18:00:00"));
            appPool.Recycling.LogEventOnRecycle = RecyclingLogEventOnRecycle.Memory
                | RecyclingLogEventOnRecycle.Requests
                | RecyclingLogEventOnRecycle.ConfigChange
                | RecyclingLogEventOnRecycle.IsapiUnhealthy
                | RecyclingLogEventOnRecycle.OnDemand
                | RecyclingLogEventOnRecycle.PrivateMemory
                | RecyclingLogEventOnRecycle.Schedule
                | RecyclingLogEventOnRecycle.Time;
            appPool.Recycling.PeriodicRestart.Memory = 40960000;
            appPool.Recycling.PeriodicRestart.PrivateMemory = 0;
            appPool.ProcessModel.IdleTimeout = TimeSpan.FromMinutes(0);
            appPool.ProcessModel.MaxProcesses = maxProcesses;
            appPool.ProcessModel.ShutdownTimeLimit = TimeSpan.FromSeconds(120);//关闭时间限制设置为120秒
            appPool.QueueLength = queueLength;
            appPool.Cpu.Limit = 80000;
            appPool.Cpu.Action = ProcessorAction.KillW3wp;
            appPool.Failure.RapidFailProtection = false;
            appPool.AutoStart = true;
            sm.CommitChanges();
            appPool.Recycle();
        }
    }
    catch
    {
        return false;
    }
    return true;
}

该文章在 2018/9/8 15:42:01 编辑过
关键字查询
相关文章
正在查询...
点晴ERP是一款针对中小制造业的专业生产管理软件系统,系统成熟度和易用性得到了国内大量中小企业的青睐。
点晴PMS码头管理系统主要针对港口码头集装箱与散货日常运作、调度、堆场、车队、财务费用、相关报表等业务管理,结合码头的业务特点,围绕调度、堆场作业而开发的。集技术的先进性、管理的有效性于一体,是物流码头及其他港口类企业的高效ERP管理信息系统。
点晴WMS仓储管理系统提供了货物产品管理,销售管理,采购管理,仓储管理,仓库管理,保质期管理,货位管理,库位管理,生产管理,WMS管理系统,标签打印,条形码,二维码管理,批号管理软件。
点晴免费OA是一款软件和通用服务都免费,不限功能、不限时间、不限用户的免费OA协同办公管理系统。
Copyright 2010-2024 ClickSun All Rights Reserved