zoukankan      html  css  js  c++  java
  • 回收应用程序池解决方法

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

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

        }
    }

  • 相关阅读:
    黄聪:解决Bootstrap模态框(modal)弹出后页面跑到顶部的办法
    黄聪:visual studio 2017编译运行出现脚本发生错误等问题如何解决?
    黄聪:xampp启动后mysql报Error
    黄聪:公众号怎么用微信做出点击此处查看答案
    黄聪:保持web页面生成的app一直处于用户登录状态不退出
    黄聪: $(document).click() 在iphone上不触发事件解决办法
    黄聪:bootstrap的模态框modal插件在苹果iOS Safari下光标偏离问题解决方案
    黄聪:pjax使用心得总结
    黄聪:Pjax无刷新跳转页面实现,支持超链接与表单提交
    黄聪:Pjax 无刷新开发web,更好用户体验
  • 原文地址:https://www.cnblogs.com/handafeng/p/IIS.html
Copyright © 2011-2022 走看看