ForEach-Object -parallel

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

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 11 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.
User avatar
SchuleDigital_HG
Posts: 5
Last visit: Tue Nov 28, 2023 6:48 am

ForEach-Object -parallel

Post by SchuleDigital_HG »

Product, version and build: Powershell Studio 2021
Operating system: Windows 10 64 Bit
PowerShell version(s): PowerShell 7.1

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:

$button1_Click={
1...5 | ForEach-Object -Parallel { start-sleep 5 } -ThrottleLimit 5

$textbox1.Text = "Finish"
}

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

So I hit "Package" and "Build". (In settings i choose Powershell 7.1.0 and Windows Forms)
(STA is OFF)
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 nothinh happen.

So my script and the processes run forever.

I hope someone can help me.
User avatar
Olga_B
Site Admin
Posts: 196
Last visit: Mon Mar 18, 2024 9:24 am

Re: ForEach-Object -parallel

Post by Olga_B »

Thanks for reporting the problem, we have been able to reproduce it and have filed a bug report with the development team.
We are investigating this and will update you as soon as we have more information
User avatar
Alexander Riedel
Posts: 8473
Last visit: Tue Mar 19, 2024 1:15 am
Answers: 19
Been upvoted: 37 times

Re: ForEach-Object -parallel

Post by Alexander Riedel »

Can you please confirm that when executed from a PowerShell 7.1 package you see 5 processes titled "Windows PowerShell" and not "pwsh" on your machine?
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
SchuleDigital_HG
Posts: 5
Last visit: Tue Nov 28, 2023 6:48 am

Re: ForEach-Object -parallel

Post by SchuleDigital_HG »

Yes its Powershell 7.1.
And Yes they are called "Windows Powershell"
User avatar
Alexander Riedel
Posts: 8473
Last visit: Tue Mar 19, 2024 1:15 am
Answers: 19
Been upvoted: 37 times

Re: ForEach-Object -parallel

Post by Alexander Riedel »

I have looked at the code for PowerShell 7 in that regard. Basically if a script is not running under pwsh.exe, they do not attempt to find it where it is supposed to be, that just default to Windows PowerShell, which obviously will not work in this case. So it seems at the moment it seems you can only use this feature when running a script, but not when packaged.
It is possible that we can do something from the hosting side of things, but obviously we would prefer if Microsoft would fix that.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 2 years and 11 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.