API Reference
Class
RunspacePool
Lightweight runspace pool with optional leak detection.
Inheritance
- Object
- RunspacePool
Remarks
The pool reuses runspaces to reduce the overhead of creating new ones on every PowerShell invocation.
Examples
using var pool = new RunspacePool();
Runspace rs = pool.Acquire();
// use runspace
pool.Release(rs);
Constructors
public RunspacePool(Boolean leakDetection = false, Nullable<Int32> maxPoolSize = null) #Creates a new runspace pool.
Parameters
- leakDetection System.Boolean = false
- Enable optional leak tracking.
- maxPoolSize System.Nullable{System.Int32} = null
- Maximum idle runspaces to retain.
Methods
public Runspace Acquire() #Returns:
RunspaceGets a runspace from the pool or creates a new one if none are available.
public Void Release(Runspace runspace) #Returns:
VoidReturns a runspace to the pool. Disposes it if the pool is full or the runspace is closed.
Parameters
- runspace System.Management.Automation.Runspaces.Runspace