Unable to cancel form while it's running

This topic contains 1 reply, has 2 voices, and was last updated by  Will Prather 2 months, 2 weeks ago.

  • Author
    Posts
  • #95856

    ImAhNoBoDy
    Participant

    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

    Will Prather
    Participant

    What you are looking for is a multi-threaded application. There's some ways of doing that, see link below.

    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.

You must be logged in to reply to this topic.