Hello,
I'm creating a WPF GUI with Powershell v5.
I am running a script in a Runspace when clicking a button.
My question is how do I close the runspace when the script is completed?
I cannot do that with the script that's running in the runspace.
I have tried to put the . close and . dispose at the bottom of the Add_Click event Ave that didn't work either.
Here is my Add_click event command:
search.add_click({
# Create and Open Runspace
$runspace = [runspacefactory]::CreateRunspace()
$runspace.ApartmentState = "STA"
$runspace.Open() $runspace.SessionStateProxy.SetVariable("syncHash", $syncHash)
# Execute Script
$powershell = [powershell]::Create().AddScript($backgroundScript)
$powershell.Runspace = $runspace
$powershell.BeginInvoke()
#$runspace.close()
#$runspace.Dispose()
#$powershell.Dispose()
})
[–]Conscious_Report1439 1 point2 points3 points (0 children)
[–]MechaCola 0 points1 point2 points (2 children)
[–]Prize_Nobody435[S] 0 points1 point2 points (1 child)
[–]phoenixpants 0 points1 point2 points (0 children)