Unable to cancel form while it's running

Welcome Forums General PowerShell Q&A Unable to cancel form while it's running

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
8 months ago.

  • Author
    Posts
  • #95856

    Participant
    Points: 1
    Rank: Member

    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?

  • #95859

    Participant
    Points: 2
    Rank: Member

    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.

The topic ‘Unable to cancel form while it's running’ is closed to new replies.