C# 关闭、开始、回收应用程序进程池

来源:互联网 发布:php的缺点 编辑:程序博客网 时间:2024/06/05 15:42

在公司的某个项目中,因为用到C++开发的第三方dll,一旦更新的时候,需要手动去回收下进程池,感觉很麻烦,于是做了这个功能,通过web管理后台来回收:

启动/停止/回收指定应用程序池源码入下;

    string AppPoolName="thylx";    //应用程序池命名,当找不到该应用程序池时,系统会报找不到指定路径

    string method="Start";            //启动命令, 停止:“Stop” ; 回收:“Recycle”

    try 

    {     
       DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools");

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

             findPool.Invoke(method,null);

             appPool.CommitChanges();

             appPool.Close(); 

             Response.Write("启动成功!");
          }

    catch(Exception ex) 

    { 

             Response.Write(string.format("发生异常:{0}",ex.ToString()));

    }

0 0