Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

RunspacePool Class

 

Updated: April 27, 2016

Applies To: Windows PowerShell

Maintains a group of runspaces that have the same characteristics and can be opened and closed on an as-needed basis. Runspace pools can be used to execute multiple commands concurrently, with each command invoked in a different runspace. This class is introduced in Windows PowerShell 2.0.

Namespace:   System.Management.Automation.Runspaces
Assembly:  System.Management.Automation (in System.Management.Automation.dll)

System.Object
  System.Management.Automation.Runspaces.RunspacePool

public sealed class RunspacePool : IDisposable

NameDescription
System_CAPS_pubpropertyApartmentState

Gets and sets the apartment state of the thread used to run the commands in the runspaces of the pool. This property is introduced in Windows PowerShell 2.0.

System_CAPS_pubpropertyCleanupInterval

Gets or sets the time interval that determines how often unused runspaces are disposed. Introduced in Windows PowerShell 3.0.

System_CAPS_pubpropertyConnectionInfo

Gets information about the connection used to open the runspaces of the pool on a computer that is typically a remote computer. This property is introduced in Windows PowerShell 2.0.

System_CAPS_pubpropertyInitialSessionState

Gets or sets information about the initial session-state used when creating the runspaces of the pool. This property is introduced in Windows PowerShell 2.0.

System_CAPS_pubpropertyInstanceId

Gets the identifier for an instance of the RunspacePool object. This property is introduced in Windows PowerShell 2.0.

System_CAPS_pubpropertyIsDisposed

Gets a value that indicates whether the RunspacePool object is disposed. When disposed, the resources used by the object are freed. This property is introduced in Windows PowerShell 2.0.

System_CAPS_pubpropertyRunspacePoolAvailability

Gets the availability of the runspace pool. Introduced in Windows PowerShell 3.0.

System_CAPS_pubpropertyRunspacePoolStateInfo

Gets information about the current state of the runspace pool. This property is introduced in Windows PowerShell 2.0.

System_CAPS_pubpropertyThreadOptions

Gets and sets how new threads are created for each runspace of the pool. This property is introduced in Windows PowerShell 2.0.

NameDescription
System_CAPS_pubmethodBeginClose(AsyncCallback, Object)

Closes the runspaces in the pool and releases all the asynchronous operations that are waiting for a runspace. If the pool is already closed, closing, or not working, this method returns without doing anything. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodBeginConnect(AsyncCallback, Object)

Connects the runspace pool asynchronously. The runspace pool must be in disconnected state. Introduced in Windows PowerShell 3.0.

System_CAPS_pubmethodBeginDisconnect(AsyncCallback, Object)

Disconnects the runspace pool asynchronously. The runspace pool must be in opened state. Introduced in Windows PowerShell 3.0.

System_CAPS_pubmethodBeginOpen(AsyncCallback, Object)

Opens the runspace pool for asynchronous operations. The pool must be opened before it can be used to create a runspace. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodClose()

Closes the runspace pool and clears all the internal resources. This method closes all open runspaces in the pool and releases any asynchronous operations that are waiting for a runspace. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodConnect()

Synchronously connects the remote runspace pool to the remote server and sets the runspace pool state to opened. If the object is a local runspace pool, a not supported exception is thrown. Introduced in Windows PowerShell 3.0.

System_CAPS_pubmethodCreateDisconnectedPowerShells()

Creates an array of PowerShell objects that are in the disconnected state for all currently disconnected running commands associated with this runspace pool. Introduced in Windows PowerShell 3.0.

System_CAPS_pubmethodDisconnect()

Synchronously disconnects the remote runspace pool from the remote server and sets the runspace pool state to disconnected. If the object is a local runspace pool, a not supported exception is thrown. Introduced in Windows PowerShell 3.0.

System_CAPS_pubmethodDispose()

Releases the resources used by the RunspacePool object. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodEndClose(IAsyncResult)

Waits for the pending BeginClose operation to be completed. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodEndConnect(IAsyncResult)

Waits for the pending asynchronous BeginConnect method call to complete. Introduced in Windows PowerShell 3.0.

System_CAPS_pubmethodEndDisconnect(IAsyncResult)

Waits for the pending asynchronous BeginDisconnect method call to complete. Introduced in Windows PowerShell 3.0.

System_CAPS_pubmethodEndOpen(IAsyncResult)

Waits for any pending asynchronous BeginOpen operation to be complete. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodEquals(Object)

(Inherited from Object.)

System_CAPS_pubmethodGetApplicationPrivateData()

Retrieves private data that is used by runspace pools opened on remote computers.

System_CAPS_pubmethodGetAvailableRunspaces()

Retrieves the number of available runspaces of the pool. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodGetCapabilities()

Retrieves the capabilities of the runspace pool. Introduced in Windows PowerShell 3.0.

System_CAPS_pubmethodGetHashCode()

(Inherited from Object.)

System_CAPS_pubmethodGetMaxRunspaces()

Retrieves the maximum number of runspaces that the pool can maintain. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodGetMinRunspaces()

Retrieves the minimum number of runspaces that Windows PowerShell will keep open. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodSystem_CAPS_staticGetRunspacePools(RunspaceConnectionInfo)

Queries the server for disconnected runspace pools by using the connection information, and creates an array of runspace pool objects associated with each disconnected runspace pool on the server. Introduced in Windows PowerShell 3.0.

System_CAPS_pubmethodSystem_CAPS_staticGetRunspacePools(RunspaceConnectionInfo, PSHost)

Queries the server for disconnected runspace pools by using the connection information and the client host, and creates an array of runspace pool objects associated with each disconnected runspace pool on the server. Introduced in Windows PowerShell 3.0.

System_CAPS_pubmethodSystem_CAPS_staticGetRunspacePools(RunspaceConnectionInfo, PSHost, TypeTable)

Queries the server for disconnected runspace pools by using the connection information, the client host, and the type table, and creates an array of runspace pool objects associated with each disconnected runspace pool on the server. Introduced in Windows PowerShell 3.0.

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_pubmethodOpen()

Opens the runspace pool for synchronous operations. The runspace pool must be opened before it can be used to create runspaces. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodSetMaxRunspaces(Int32)

Sets the maximum number of runspaces that the pool can maintain at one time. All requests greater than that number remain queued until runspaces become available. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodSetMinRunspaces(Int32)

Sets the minimum number of runspaces that Windows PowerShell will keep open. By default, Windows PowerShell will keep a single runspace open. This method is introduced in Windows PowerShell 2.0.

System_CAPS_pubmethodToString()

(Inherited from Object.)

NameDescription
System_CAPS_pubeventStateChanged

Occurs when the state of the runspace pool changes. This event is introduced in Windows PowerShell 2.0.

A runspace is an environment where commands can be run. Each runspace has a global session-state, plus session-states for any modules that are loaded in the runspace.

System_CAPS_noteNote

From a user’s perspective, a runspace is the session that they are currently using or a PSSession that they have created on a computer.

To create a runspace pool, call the CreateRunspacePool method of the RunspaceFactory class. You can create a pool of runspaces on the local computer or a remote computer.

This class cannot be inherited.

This example shows how to create a runspace pool object that has a single runspace, open the runspace, use a PowerShell object to run commands in the runspace, how to close the runspace, and then how to dispose the runspace pool object to free resources.

using (RunspacePool rsp = RunspaceFactory.CreateRunspacePool())
{
  rsp.Open();

  // Create a PowerShell object to run the following command.
  //  get-process wmi*
  PowerShell gpc = PowerShell.Create();        
  // Specify the runspace to use and add commands.
  gpc.RunspacePool = rsp;
  gpc.AddCommand("Get-Process").AddArgument("wmi*");

  // Invoke the command asynchronously. 
  IAsyncResult gpcAsyncResult = gpc.BeginInvoke();
  // Get the results of running the command. 
  PSDataCollection<PSObject> gpcOutput = gpc.EndInvoke(gpcAsyncResult);

  // Process the output.
  Console.WriteLine("The output from running the command: get-process wmi*");
  for (int i= 0; i < gpcOutput.Count; i++)
  {
   Console.WriteLine(
                     "Process Name: {0} Process Id: {1}",
                     gpcOutput[i].Properties["ProcessName"].Value,
                     gpcOutput[i].Properties["Id"].Value);
  }

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: