zoukankan      html  css  js  c++  java
  • IIS进程资源定期回收

    IIS6常见的性能调优方案中设置进程自动回收时间就是一种方法,用代码同样可以实现之,或者在什么样的时间有选择性的回收指定的应用程序池:

    使用C#代码操作的就是上图中的回收工作进程,单位分钟,默认好像是1740分钟吧,没有意义:

    using System.DirectoryServices; //先引用此命名空间IIS7据说已经是有新的API

    private void button1_Click(object sender, EventArgs e)

    {

    string method = this.comboBox1.Text; //Start开启 Recycle回收 Stop 停止

    string AppPoolName = this.comboBox2.Text;

    if (method == "")

    {

    this.label4.Text = "AppPoolName and method is required!";

    return;

    }

    if (AppPoolName == "")

    {

    this.label4.Text = "AppPoolName and method is required!";

    return;

    }

    try

    {

    DirectoryEntry appPool = new DirectoryEntry(this.textBox2.Text.Trim());

    DirectoryEntry findPool = appPool.Children.Find(AppPoolName, "IIsApplicationPool");

     findPool.Invoke(method, null);

     appPool.CommitChanges();

     appPool.Close();

     MessageBox.Show("应用程序池(" + method + ")操作成功", "启动成功", MessageBoxButtons.OK,

    MessageBoxIcon.Information);

    }

    catch (Exception ex)

    {

    MessageBox.Show(ex.Message, "启动失败", MessageBoxButtons.OK, MessageBoxIcon.Error);

    }

    }

    private void Form1_Load(object sender, EventArgs e)

    {

    try

    {

    DirectoryEntry appPool = new DirectoryEntry(this.textBox2.Text.Trim());

    foreach (DirectoryEntry dirPool in appPool.Children)

    {

    if (dirPool.SchemaClassName == "IIsApplicationPool")

    {

    comboBox2.Items.Add(dirPool.Name);

    }

    }

    }

    catch (Exception ex)

    { }

    }

    写成Window Service 或者Console给计划任务定期跑就可以了。

    msn: pccai1983@hotmail.com
  • 相关阅读:
    MySQL存储过程和函数
    MySQL数据类型
    MySQL—基础(SQL语句)
    如何将一串字符串按照某个特定的字符分割后倒叙输出,如:www.baidu.com输出为com.baidu.www
    JAVA WEB数据中文编码问题
    如何用一条SQL语句从登录日志表中查询统计出每个人登录的次数
    JAVA WEB tomcat启动关闭问题
    thinkphp知识点
    smarty模板内容
    smarty基础
  • 原文地址:https://www.cnblogs.com/pccai/p/1977631.html
Copyright © 2011-2022 走看看