mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2026-08-09 17:41:14 +10:00
* Harden Pester CI and discard runspace return values * Add prioritized test backlog * Add WinUtil action logging * Add config integrity tests * Add XAML control wiring tests * Add registry and service helper tests * Add package manager tests * Add runspace behavior tests * Add tweak orchestration tests * Add install workflow tests * Add update profile tests * Add AppX removal tests * Log package installer output * Add UI state helper tests * Pin Pester test runner version * Expand Win11 Creator tests * Add preferences and theme tests * Add search filter tests * Add compile contract tests * Use single WinUtil session log * Remove installer output logging helper * Handle locked WinUtil transcript log * Avoid appending to active transcript log * Log install uninstall package identities
60 lines
1.7 KiB
PowerShell
60 lines
1.7 KiB
PowerShell
function Invoke-WPFRunspace {
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
Creates and invokes a runspace using the given scriptblock and argumentlist
|
|
|
|
.PARAMETER ScriptBlock
|
|
The scriptblock to invoke in the runspace
|
|
|
|
.PARAMETER ArgumentList
|
|
A list of arguments to pass to the runspace
|
|
|
|
.PARAMETER ParameterList
|
|
A list of named parameters that should be provided.
|
|
.EXAMPLE
|
|
Invoke-WPFRunspace `
|
|
-ScriptBlock $sync.ScriptsInstallPrograms `
|
|
-ArgumentList "Installadvancedip,Installbitwarden" `
|
|
|
|
Invoke-WPFRunspace`
|
|
-ScriptBlock $sync.ScriptsInstallPrograms `
|
|
-ParameterList @(("PackagesToInstall", @("Installadvancedip,Installbitwarden")),("ChocoPreference", $true))
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
Param (
|
|
$ScriptBlock,
|
|
$ArgumentList,
|
|
$ParameterList
|
|
)
|
|
|
|
# Create a PowerShell instance
|
|
$script:powershell = [powershell]::Create()
|
|
|
|
# Add Scriptblock and Arguments to runspace
|
|
[void]$script:powershell.AddScript($ScriptBlock)
|
|
[void]$script:powershell.AddArgument($ArgumentList)
|
|
|
|
foreach ($parameter in $ParameterList) {
|
|
[void]$script:powershell.AddParameter($parameter[0], $parameter[1])
|
|
}
|
|
|
|
$script:powershell.RunspacePool = $sync.runspace
|
|
|
|
# Execute the RunspacePool
|
|
$script:handle = $script:powershell.BeginInvoke()
|
|
|
|
# Clean up the RunspacePool threads when they are complete, and invoke the garbage collector to clean up the memory
|
|
if ($script:handle.IsCompleted) {
|
|
$script:powershell.EndInvoke($script:handle)
|
|
$script:powershell.Dispose()
|
|
$sync.runspace.Dispose()
|
|
$sync.runspace.Close()
|
|
[System.GC]::Collect()
|
|
}
|
|
# Return the handle
|
|
return $handle
|
|
}
|