亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何編寫.net重啟iis線程池和iis站點程序代碼

發布時間:2021-10-08 15:34:47 來源:億速云 閱讀:128 作者:iii 欄目:開發技術

本篇內容主要講解“如何編寫.net重啟iis線程池和iis站點程序代碼”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“如何編寫.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;
        }

到此,相信大家對“如何編寫.net重啟iis線程池和iis站點程序代碼”有了更深的了解,不妨來實際操作一番吧!這里是億速云網站,更多相關內容可以進入相關頻道進行查詢,關注我們,繼續學習!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

岱山县| 临泉县| 罗源县| 剑阁县| 南郑县| 海阳市| 邹平县| 奈曼旗| 镇远县| 吴江市| 九寨沟县| 晋宁县| 绍兴市| 织金县| 长子县| 凤阳县| 松溪县| 玉环县| 尤溪县| 德清县| 金乡县| 罗定市| 聊城市| 舞阳县| 宁津县| 台州市| 平遥县| 泾阳县| 阳江市| 苍南县| 新和县| 龙胜| 吴川市| 开封县| 尚义县| 平谷区| 雅安市| 逊克县| 蒲城县| 滦平县| 嘉祥县|