本文整理汇总了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;
}
示例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);
}
示例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;
}
}
示例4: getAnotherRunspace
internal Runspace getAnotherRunspace(Runspace existingRunspace)
{
returnRunspace(existingRunspace, false);
existingRunspace.Dispose();
return acquireRunspace();
}
示例5: CloseRunspace
internal static void CloseRunspace(Runspace runspace)
{
runspace.Dispose();
}
示例6: RecommitToRunspacePool
private void RecommitToRunspacePool(Runspace runspace) {
if (runspacePool.Count > 3) {
runspace.Dispose();
return;
}
runspacePool.Add(runspace);
}