Runspace GetWPFCurrentThreadRunspace(InitialSessionState sessionState) { InitialSessionState clone = sessionState.Clone(); clone.ThreadOptions = PSThreadOptions.UseCurrentThread; SessionStateVariableEntry window = new SessionStateVariableEntry("Window", JobWindow, ""); SessionStateVariableEntry namedControls = new SessionStateVariableEntry("NamedControls", this.namedControls, ""); clone.Variables.Add(window); clone.Variables.Add(namedControls); return(RunspaceFactory.CreateRunspace(clone)); }
public RunspacePoolInternal( int minRunspaces, int maxRunspaces, InitialSessionState initialSessionState, PSHost host) : this(minRunspaces, maxRunspaces) { using (RunspacePoolInternal.tracer.TraceConstructor((object)this)) { if (initialSessionState == null) { throw RunspacePoolInternal.tracer.NewArgumentNullException(nameof(initialSessionState)); } if (host == null) { throw RunspacePoolInternal.tracer.NewArgumentNullException(nameof(host)); } this._initialSessionState = initialSessionState.Clone(); this.host = host; this.pool = new Stack <Runspace>(); this.runspaceRequestQueue = new Queue <GetRunspaceAsyncResult>(); this.ultimateRequestQueue = new Queue <GetRunspaceAsyncResult>(); } }
/// <summary> /// Constructor which creates a RunspacePool using the /// supplied <paramref name="configuration"/>, <paramref name="minRunspaces"/> /// and <paramref name="maxRunspaces"/> /// </summary> /// <param name="initialSessionState"> /// InitialSessionState to use when creating a new Runspace. /// </param> /// <param name="maxRunspaces"> /// The maximum number of Runspaces that can exist in this pool. /// Should be greater than or equal to 1. /// </param> /// <param name="minRunspaces"> /// The minimum number of Runspaces that can exist in this pool. /// Should be greater than or equal to 1. /// </param> /// <param name="host"> /// The explicit PSHost implementation. /// </param> /// <exception cref="ArgumentNullException"> /// initialSessionState is null. /// Host is null. /// </exception> /// <exception cref="ArgumentException"> /// Maximum runspaces is less than 1. /// Minimum runspaces is less than 1. /// </exception> public RunspacePoolInternal(int minRunspaces, int maxRunspaces, InitialSessionState initialSessionState, PSHost host) : this(minRunspaces, maxRunspaces) { if (initialSessionState == null) { throw PSTraceSource.NewArgumentNullException("initialSessionState"); } if (host == null) { throw PSTraceSource.NewArgumentNullException("host"); } _initialSessionState = initialSessionState.Clone(); this.host = host; ThreadOptions = initialSessionState.ThreadOptions; #if !CORECLR // No ApartmentState In CoreCLR this.ApartmentState = initialSessionState.ApartmentState; #endif pool = new Stack<Runspace>(); runspaceRequestQueue = new Queue<GetRunspaceAsyncResult>(); ultimateRequestQueue = new Queue<GetRunspaceAsyncResult>(); }