• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    .net重启iis线程池和iis站点程序代码分享

    重启站点:

    复制代码 代码如下:

     /// summary>
            /// 根据名字重启站点.(没重启线程池)
            /// /summary>
            /// param name="sitename">/param>
            static void RestartWEbSite(string sitename)
            {
                try
                {
                    var server = new ServerManager();
                    var site = server.Sites.FirstOrDefault(s => s.Name == sitename);
                    if (site != null)
                    {
                        site.Stop();
                        if (site.State == ObjectState.Stopped)
                        {
                        }
                        else
                        {
                            Console.WriteLine("Could not stop website!");
                            throw new InvalidOperationException("Could not stop website!");
                        }
                        site.Start();
                    }
                    else
                    {
                        Console.WriteLine("Could not find website!");

                        throw new InvalidOperationException("Could not find website!");
                    }

                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }

            /// summary>
            /// 重启完之后.要再检测下.是否开启了
            /// /summary>
            /// param name="sitename">/param>
            static void FixWebsite(string sitename)
            {
                try
                {
                    var server = new ServerManager();
                    var site = server.Sites.FirstOrDefault(s => s.Name == sitename);
                    if (site != null)
                    {
                        if (site.State != ObjectState.Started)
                        {
                            Thread.Sleep(500);

                            //防止状态为正在开启
                            if (site.State != ObjectState.Started)
                            {
                                site.Start();
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }

    重启iis线程池:

    复制代码 代码如下:

    /// summary>
            /// 线程池名字
            /// /summary>
            /// param name="name">/param>
            static void RestartIISPool(string name)
            {
                string[] cmds = { "c:", @"cd %windir%\system32\inetsrv", string.Format("appcmd stop apppool /apppool.name:{0}", name), string.Format("appcmd start apppool /apppool.name:{0}", name) };
                Cmd(cmds);
                CloseProcess("cmd.exe");
            }

            /// summary>
            /// 运行CMD命令
            /// /summary>
            /// param name="cmd">命令/param>
            /// returns>/returns>
            public static string Cmd(string[] cmd)
            {
                Process p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.CreateNoWindow = true;
                p.Start();
                p.StandardInput.AutoFlush = true;
                for (int i = 0; i cmd.Length; i++)
                {
                    p.StandardInput.WriteLine(cmd[i]);
                }
                p.StandardInput.WriteLine("exit");

                string strRst = p.StandardOutput.ReadToEnd();

                //Debug.Print(strRst);

                p.WaitForExit();
                p.Close();
                return strRst;
            }

            /// summary>
            /// 关闭进程
            /// /summary>
            /// param name="ProcName">进程名称/param>
            /// returns>/returns>
            public static bool CloseProcess(string ProcName)
            {
                bool result = false;
                var procList = new ArrayList();
                foreach (Process thisProc in Process.GetProcesses())
                {
                    var tempName = thisProc.ToString();
                    int begpos = tempName.IndexOf("(") + 1;
                    int endpos = tempName.IndexOf(")");
                    tempName = tempName.Substring(begpos, endpos - begpos);
                    procList.Add(tempName);
                    if (tempName == ProcName)
                    {
                        if (!thisProc.CloseMainWindow())
                            thisProc.Kill(); // 当发送关闭窗口命令无效时强行结束进程
                        result = true;
                    }
                }
                return result;
            }

    您可能感兴趣的文章:
    • C#实现线程池的简单示例
    • c++版线程池和任务池示例
    • C#线程池用法详细介绍
    • 利用ace的ACE_Task等类实现线程池的方法详解
    • 在Android线程池里运行代码任务实例
    • 支持生产阻塞的Java线程池
    • python线程池的实现实例
    • 线程池的原理与实现详解
    • 深入java线程池的使用详解
    • java中通用的线程池实例代码
    • Java代码构建一个线程池
    • C++线程池的简单实现方法
    上一篇:利用noesis.Javascript开源组件.Net中执行javascript脚本
    下一篇:.net实现微信公众账号接口开发实例代码
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯 版权所有

    《增值电信业务经营许可证》 苏ICP备15040257号-8

    .net重启iis线程池和iis站点程序代码分享 .net,重启,iis,线程,池,和,