本文介绍了如何在C#中停止各种应用程序池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想在c#中停止应用程序池。但是我得到了异常 未知错误(0x80005000)。 我尝试了什么: #region IIS内存管理停止池//由Mathew在19 /上添加06/2017 public bool StopPool(string appPoolName) { string errorPath = ConfigurationManager.AppSettings [SERVICE_ERROR_PATH]。ToString()。Trim(); string ErrorFile =Application_Pool_Reset_+ DateTime.Now.ToString(ddMMyyyy)+。txt; 尝试 { Common.WriteTextFile(errorPath + ErrorFile,----------------------- -------------------------------------------------- --------------------------- + Environment.NewLine); if(appPoolName == null) {抛出新的ArgumentNullException(applicationPoolName); } //使用(DirectoryEntry applicationPool = new // DirectoryEntry(IIS:// localhost / W3SVC / AppPools /+ appPoolName)) / / { // Common.WriteTextFile(errorPath + ErrorFile,----------------------------- Stopping Application Pool + appPoolName +---------------------------------------------- - ); // applicationPool.Invoke(停止); // Common.WriteTextFile(errorPath + ErrorFile,-----------------------------停止调用应用程序池+ appPoolName +----------------------------------------------- - ); //} string appPoolPath = @IIS://+ System.Environment.MachineName +/ W3SVC / AppPools /+ appPoolName; try { DirectoryEntry w3svc = new DirectoryEntry(appPoolPath); w3svc.Invoke(Stop,null); // status(); } catch(Exception ex) { //Response.Write(ex.ToString()); } //Common.WriteTextFile(errorPath + ErrorFile,DateTime.Now.ToString(yyy-MM-dd HH:mm:ss)+ Environment.NewLine +Service Hanging监控结束......+ Environment.NewLine); } catch(exception ex) { Common.WriteTextFile(errorPath,StopPool()中的错误.Sys。错误:+ ex.Message + ex.StackTrace) ; 返回false; } 返回true; } 解决方案 I am trying to stop Application Pool in c#.But I am getting the exception "Unknown error (0x80005000)".What I have tried:#region IIS Memory Management Stop Pool//Added by Mathew on 19/06/2017 public bool StopPool(string appPoolName) { string errorPath = ConfigurationManager.AppSettings["SERVICE_ERROR_PATH"].ToString().Trim(); string ErrorFile = "Application_Pool_Reset_" + DateTime.Now.ToString("ddMMyyyy") + ".txt"; try { Common.WriteTextFile(errorPath + ErrorFile, "----------------------------------------------------------------------------------------------------" + Environment.NewLine); if (appPoolName == null) { throw new ArgumentNullException("applicationPoolName"); } //using (DirectoryEntry applicationPool = new //DirectoryEntry("IIS://localhost/W3SVC/AppPools/" + appPoolName)) //{ // Common.WriteTextFile(errorPath + ErrorFile, "-----------------------------Stopping Application Pool " + appPoolName + " ------------------------------------------------"); // applicationPool.Invoke("Stop"); // Common.WriteTextFile(errorPath + ErrorFile, "-----------------------------Stop Application Pool Invoked" + appPoolName + " ------------------------------------------------"); //} string appPoolPath = @"IIS://" + System.Environment.MachineName + "/W3SVC/AppPools/" + appPoolName; try { DirectoryEntry w3svc = new DirectoryEntry(appPoolPath); w3svc.Invoke("Stop", null); // status(); } catch (Exception ex) { //Response.Write(ex.ToString()); } //Common.WriteTextFile(errorPath + ErrorFile, DateTime.Now.ToString("yyy-MM-dd HH:mm:ss") + Environment.NewLine + "Service Hanging Monitoring End..." + Environment.NewLine); } catch (Exception ex) { Common.WriteTextFile(errorPath, "Error in StopPool(). Sys. Error:" + ex.Message + ex.StackTrace); return false; } return true; } 解决方案 这篇关于如何在C#中停止各种应用程序池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-27 08:29