Powershell threading vs C# threading Powershell threading vs C# threading powershell powershell

Powershell threading vs C# threading


If I put this inside a click event of a button

$PowerShell.Invoke() executes synchronously, so it will by definition block until the script you've added completes, so it will freeze the GUI.

nothing happens.

Write-Host $test (in PSv5+) writes to the information stream (stream number 6), which is not directly returned by an .Invoke() call - only success output (stream number 1) is; see about_Redirection.

Additionally, even if there were success output, outputting to the success stream from an event handler will not surface in the console (terminal).


If you had a task where you had to call a function that does some work and updates a GUI. How would you go about calling that function in its own thread so that the GUI won't freeze while it's working in Powershell?

See the following WPF-based answer, which can be adapted to WinForms with relatively little effort.