mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-15 15:15:51 -06:00
14d20cd161
* First Selector and Logic * Extend Functionality * Switch to PreferChocolatey Checkbox * Persist Choco Preference across program restarts * Change Logging, Fix interactivity and optimize uninstall * Implement "Get-Installed" (quick-and-dirty) * Code Formatting * Rename File/Function, Refactor Choco Install, Add Status Indicator * Add documentation --------- Co-authored-by: Chris Titus <contact@christitus.com>
51 lines
1.4 KiB
PowerShell
51 lines
1.4 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
|
|
|
|
.EXAMPLE
|
|
Invoke-WPFRunspace `
|
|
-ScriptBlock $sync.ScriptsInstallPrograms `
|
|
-ArgumentList "Installadvancedip,Installbitwarden" `
|
|
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
Param (
|
|
$ScriptBlock,
|
|
$ArgumentList,
|
|
$DebugPreference
|
|
)
|
|
|
|
# Create a PowerShell instance
|
|
$script:powershell = [powershell]::Create()
|
|
|
|
# Add Scriptblock and Arguments to runspace
|
|
$script:powershell.AddScript($ScriptBlock)
|
|
foreach ($Argument in $ArgumentList) {
|
|
$script:powershell.AddArgument($Argument)
|
|
}
|
|
$script:powershell.AddArgument($DebugPreference) # Pass DebugPreference to the script block
|
|
$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()
|
|
}
|
|
}
|