91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

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

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

如何編寫.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

扶余县| 白山市| 上高县| 娱乐| 无棣县| 观塘区| 井研县| 台山市| 桃源县| 河间市| 曲靖市| 含山县| 勐海县| 抚顺市| 琼结县| 四子王旗| 平安县| 上思县| 呼玛县| 五指山市| 综艺| 乡宁县| SHOW| 饶阳县| 锡林浩特市| 出国| 图木舒克市| 秦皇岛市| 哈巴河县| 合阳县| 顺平县| 北京市| 永宁县| 梧州市| 扬州市| 绥化市| 昌吉市| 宣恩县| 新竹市| 大悟县| 子长县|