mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2026-07-16 00:40:39 +00:00
* Clean up analyzer warnings * Align analyzer warning cleanup policy * Run PSScriptAnalyzer directly in unittests workflow * Bind lazy-rendered buttons to click handlers * Remove WinUtil performance tracing * Fix Win11 ISO creator temp directory reuse
39 lines
1.8 KiB
PowerShell
39 lines
1.8 KiB
PowerShell
function Initialize-WinUtilRunspacePool {
|
|
if ($sync.runspace -and $sync.runspace.RunspacePoolStateInfo.State -eq [System.Management.Automation.Runspaces.RunspacePoolState]::Opened) {
|
|
return $sync.runspace
|
|
}
|
|
|
|
if ($sync.runspace) {
|
|
Close-WinUtilRunspacePool
|
|
}
|
|
|
|
# Set the maximum number of threads for the RunspacePool to the number of threads on the machine.
|
|
$maxthreads = [Math]::Max([int]$env:NUMBER_OF_PROCESSORS, 1)
|
|
|
|
# Create a new session state for parsing variables into our runspace.
|
|
$hashVars = New-Object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'sync', $sync, $null
|
|
$offlineVar = New-Object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'PARAM_OFFLINE', $PARAM_OFFLINE, $null
|
|
$initialSessionState = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
|
|
|
|
$initialSessionState.Variables.Add($hashVars)
|
|
$initialSessionState.Variables.Add($offlineVar)
|
|
|
|
# Get every WinUtil/WPF function and add it to the session state.
|
|
$functions = Get-ChildItem function:\ | Where-Object { $_.Name -imatch 'winutil|WPF' }
|
|
foreach ($function in $functions) {
|
|
$functionDefinition = Get-Content function:\$($function.Name)
|
|
$functionEntry = New-Object System.Management.Automation.Runspaces.SessionStateFunctionEntry -ArgumentList $function.Name, $functionDefinition
|
|
$initialSessionState.Commands.Add($functionEntry)
|
|
}
|
|
|
|
$sync.runspace = [runspacefactory]::CreateRunspacePool(
|
|
1, # Minimum thread count
|
|
$maxthreads, # Maximum thread count
|
|
$initialSessionState, # Initial session state
|
|
$Host # Machine to create runspaces on
|
|
)
|
|
|
|
$sync.runspace.Open()
|
|
return $sync.runspace
|
|
}
|