当前位置: 首页>>代码示例>>C#>>正文


C# Runspace.Dispose方法代码示例

本文整理汇总了C#中System.Management.Automation.Runspaces.Runspace.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Runspace.Dispose方法的具体用法?C# Runspace.Dispose怎么用?C# Runspace.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.Automation.Runspaces.Runspace的用法示例。


在下文中一共展示了Runspace.Dispose方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: getRunspace

        private static Runspace getRunspace()
        {
            if (runspace != null)
                return runspace;
            RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create();
	        PSSnapInException ex = null;
	        PSSnapInInfo pSSnapInInfo = null;

            // Exchange 2007
	        try
	        {
		        pSSnapInInfo = runspaceConfiguration.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.Admin", out ex);
	        }
	        catch {}

            // Exchange 2010 
	        try
	        {
		        pSSnapInInfo = runspaceConfiguration.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.E2010", out ex);
	        }
	        catch {}

            // Exchange 2013
    	    try
	        {
		        pSSnapInInfo = runspaceConfiguration.AddPSSnapIn("Microsoft.Exchange.Management.PowerShell.SnapIn", out ex);
	        }
	        catch {}
    
            if (pSSnapInInfo != null)
            {
                Exception except = null;

                try
                {
                    runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration);
                    runspace.Open();
                }
                catch (Exception exc)
                {
                    except = exc;
                    runspace.Dispose();
                    runspace = null;
                }
                if (except != null)
                    throw except;
            }
            else
            {
                throw new ExchangeServerException("Couldn't initialize PowerShell Runspace");
            }

            return runspace;
        }
开发者ID:Benjile,项目名称:dkim-exchange,代码行数:54,代码来源:PowershellHelper.cs

示例2: ExecPowerShellCommand

        public static string ExecPowerShellCommand(string sCommand, bool bRemoveEmptyLines)
        {
            if (runspace == null)
            {
                PSSnapInInfo info = null;
                PSSnapInException ex = null;
                bool error = false;

                try
                {
                    runspace = RunspaceFactory.CreateRunspace(RunspaceConfiguration.Create());
                    runspace.Open();

                    foreach (string pssnapin in ExchangePsSnapin)
                    {
                        if (Execute("$(Get-PSSnapin -Registered | Select-String " + pssnapin + ") -ne $null", true).Trim() == "True")
                        {
                            info = runspace.RunspaceConfiguration.AddPSSnapIn(pssnapin, out ex);
                        }
                    }
                }
                catch (Exception)
                {
                    error = true;
                }

                if (ex != null || info == null || error)
                {
                    if (runspace != null)
                    {
                        runspace.Dispose();
                        runspace = null;
                    }
                    throw new ExchangeServerException("Couldn't initialize PowerShell runspace.");
                }
            }

            return Execute(sCommand, bRemoveEmptyLines);
        }
开发者ID:DennyMei,项目名称:dkim-exchange,代码行数:39,代码来源:PowershellHelper.cs

示例3: DestroyRunspace

 protected void DestroyRunspace(Runspace runspace)
 {
     runspace.Events.ForwardEvent -= new EventHandler<PSEventArgs>(this.OnRunspaceForwardEvent);
     runspace.Close();
     runspace.Dispose();
     lock (this.runspaceList)
     {
         this.runspaceList.Remove(runspace);
         this.totalRunspaces = this.runspaceList.Count;
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:11,代码来源:RunspacePoolInternal.cs

示例4: getAnotherRunspace

 internal Runspace getAnotherRunspace(Runspace existingRunspace)
 {
     returnRunspace(existingRunspace, false);
     existingRunspace.Dispose();
     return acquireRunspace();
 }
开发者ID:Evolveum,项目名称:openicf,代码行数:6,代码来源:PowerShellSupport.cs

示例5: CloseRunspace

 internal static void CloseRunspace(Runspace runspace)
 {
     runspace.Dispose();
 }
开发者ID:PowerShell,项目名称:SmartPackageProvider,代码行数:4,代码来源:DscInvoker.cs

示例6: RecommitToRunspacePool

 private void RecommitToRunspacePool(Runspace runspace) {
     if (runspacePool.Count > 3) {
         runspace.Dispose();
         return;
     }
     runspacePool.Add(runspace);
 }
开发者ID:nickguletskii,项目名称:SchoolCommander,代码行数:7,代码来源:InternetConnectionStatus.cs


注:本文中的System.Management.Automation.Runspaces.Runspace.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。