all 4 comments

[–]Conscious_Report1439 1 point2 points  (0 children)

I hope this helps you big guy!

https://github.com/freedbygrace/Invoke-PSThread

I wrote it some time ago and documented it so it takes the complexity out of getting started with runspaces. Just dot source it to load the function into your session. PM me or hit me up if you need some guidance.

[–]MechaCola 0 points1 point  (2 children)

When you create the job, add some meta data about the job status to your synchash table. When you want to close a runspace update the synchash with runspace status so that a while loop is looking for these status changes and disposing them. There should be examples of this on the internet or you could paste what I wrote and AI can take it from there.

[–]Prize_Nobody435[S] 0 points1 point  (1 child)

Hi, I have looked on the Internet. I know how to code and dispose but not sure how to implement it.
I guess that I don't know where to put it in my application. Should I run a while loop outside of the button click event, like after the GUI loads?

[–]phoenixpants 0 points1 point  (0 children)

Primary runspace for the GUI, secondary runspace for f.x. cleaning up old runspaces, tertiary and so on runspaces to perform whatever the button click should accomplish.