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.
This topic is 2 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
SchuleDigital_HG
Posts: 5
Last visit: Tue Nov 28, 2023 6:48 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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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: Tue Nov 28, 2023 6:48 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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 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.
This topic is 2 years and 10 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked