• 回收应用程序池解决方法


       以下程序就是实现自动关闭并回收应用程序缓冲池。

    App.config内容

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <!-- 程序运行时隔(单位:毫秒) -->
        <add key ="TimeSpan" value ="10000"/>
        <!-- 要监视的进程(不加.exe),默认是vsjitdebugger -->
        <add key ="AppName" value ="zhaoPin.ClientServiceV2"/>
        <!-- 要回收的应用程序池名称 -->
        <add key ="Appool" value ="zhaoPin.Rc"/>
      </appSettings>
    </configuration>

    using System;
    using System.Diagnostics;
    using System.Configuration;
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                int i = 0;
                bool tag=false;
                Console.WriteLine("请不要关闭此窗口!!");
                string dd = System.Configuration.ConfigurationManager.AppSettings["TimeSpan"].ToString();
                string appname = System.Configuration.ConfigurationManager.AppSettings["AppName"].ToString();
                string appool = System.Configuration.ConfigurationManager.AppSettings["Appool"].ToString();
                while (true)
                {
                    System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcesses();
                    foreach (Process pi in p)
                        if (pi.ProcessName == appname)
                        {
                            tag=true;
                            pi.Kill();
                        }
                    if (tag)
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        i++;
                        string msg = RecycleAppol(appool);
                        Console.WriteLine("成功关闭" + i + "次!!");
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine(msg);
                        tag = false;
                    }
                    System.Threading.Thread.Sleep(Convert.ToInt32(dd));
                }
            }
            static string RecycleAppol(string appoolname)
            {
                Process p = new Process();
                p.StartInfo.FileName = "cscript.exe";
                p.StartInfo.Arguments = "c:\windows\system32\iisapp.vbs /a "+appoolname+" /r";
                p.StartInfo.CreateNoWindow = false;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.Start();
                return p.StandardOutput.ReadToEnd();
            }

        }
    }

  • 相关阅读:
    java一个字符串中出现次数最多的字符以及次数
    按要求分解字符串,输入两个数M,N;M代表输入的M串字符串,N代表输出的每串字符串的位数,不够补0。例如:输入2,8, “abc” ,“123456789”,则输出为“abc00000”,“12345678“,”90000000”
    Java 替换空格
    Java中equals()和“==”区别
    ramfs和tmpfs的区别
    C语言中的nan和inf使用
    Abp中SwaggerUI的多个接口文档配置说明
    Abp中SwaggerUI的接口说明文档配置
    Abp中SwaggerUI的接口文档添加上传文件参数类型
    Abp中自定义Exception的HttpStatusCode
  • 原文地址:https://www.cnblogs.com/handafeng/p/IIS.html
Copyright © 2020-2023  润新知