Author Posts

March 14, 2018 at 2:16 am

I have a PowersShell form that has a start button with a few functions:

$StartButton.Add_Click({
Test1
Test2
Test3
Test4
Test5
})

While the script is calling the functions in the background, I am unable to interact with GUI. More specifically, I am unable to click on the cancel button to cancel/exit the script at anytime. The only time I can cancel the form is when it is completely finished running all the functions. Are there any ways to keep my start button active and cancel my form at any time?

March 14, 2018 at 2:29 am

What you are looking for is a multi-threaded application. There's some ways of doing that, see link below.
Part V – Building Responsive PowerShell Apps with Progress bars

Stephen Owen wrote the above blog. It's really useful in describing how to use multiple runspaces in your application. I won't lie though, even after reading the blog, it took me a little while to fully grasp the concept and apply it myself.