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给计划任务定期跑就可以了。


__EOF__

本文作者pccai
本文链接https://www.cnblogs.com/pccai/archive/2011/03/08/1977631.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   pccai  阅读(3684)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示