Using the InitialSessionState and RunspacePool objects

The RunspacePool object can be created using RunspaceFactoryRunspacePool can be created with either the minimum and maximum number of concurrent threads, or an InitialSessionState object. Creating the pool using an InitialSessionState object is shown here:

$initialSessionState = [InitialSessionState]::CreateDefault2()
$runspacePool = [RunspaceFactory]::CreateRunspacePool($initialSessionState)

Any extra entries required in the InitialSessionState must either be added using the $intialSessionState variable before RunspacePool is created, or extra entries must be added using $runspacePool.InitialSessionState after RunspacePool is created. Changes cannot be made after RunspacePool has been opened.

If RunspacePool is created with InitialSessionState, the SetMinRunspaces and SetMaxRunspaces methods can be used to adjust the minimum and maximum number of threads. The default value for both the minimum and maximum is 1. The following example changes the maximum:

$runspacePool.SetMaxRunspaces(5)

The GetMinRunspaces and GetMaxRunspaces methods may be used to retrieve the current values. 

RunspacePool is then used as shown in the Using the RunspacePool object section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.160.216