ForEach-Object -parallel

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Post Reply
User avatar
SchuleDigital_HG
Posts: 5
Last visit: Fri May 07, 2021 10:58 am

ForEach-Object -parallel

Post by SchuleDigital_HG »

Hallo,

i have a problem with the new PowerShell7 Feature "ForEach-Object -parallel !!!!

I tryed a lot of thinks, but nothing workted for me, I hope you can help.

I try this code:

1 .. 5 | ForEach-Object -Parallel { "Hello $_"; sleep 2; } -ThrottleLimit 5
$textbox1.Text = "Fertig"


In PowerShellStudio 2021 i select V7 - 64 Bit and hit run. Everythink good, no Problem.

So I hit "Package" and "Build". (In settings i choose Powershell 7.1.0 and Windows Forms)
Than I hit the EXE File. The Programm Starts, but I never come to the point of "$textbox1.text".
In the Taskmanager I can see that 5 new Processes are started called "Windows Powershell", but nothink happen.

So my script and the processes run forever.

I hope someone can help me.

jvierra
Posts: 14790
Last visit: Sat May 15, 2021 11:18 am
Answers: 9
Has voted: 3 times
Been upvoted: 9 times

Re: ForEach-Object -parallel

Post by jvierra »

Do not use STA mode. Also do not place code outside of an event and do not use the Load" event. Start by using a button.

User avatar
SchuleDigital_HG
Posts: 5
Last visit: Fri May 07, 2021 10:58 am

Re: ForEach-Object -parallel

Post by SchuleDigital_HG »

Thank you.

But this don´t work for me.

I switchted off the STA Mode in Powershell Studio and in the Packager. The script I posted is in an event of an button.

jvierra
Posts: 14790
Last visit: Sat May 15, 2021 11:18 am
Answers: 9
Has voted: 3 times
Been upvoted: 9 times

Re: ForEach-Object -parallel

Post by jvierra »

Since it works in a script but not when packaged I suspect there is a mismatch to the packaging engine. You might want to ask the question in the PSS product support forum.

thinkappleten
Posts: 1
Last visit: Wed Apr 21, 2021 12:06 am

Re: ForEach-Object -parallel

Post by thinkappleten »

I switchted off the STA Mode in Powershell Studio and in the Packager.

Post Reply