GUI closing after script run

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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 5 years and 7 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
Tony67
Posts: 5
Last visit: Wed Mar 24, 2021 6:28 pm

GUI closing after script run

Post by Tony67 »

Hello all,

I have a gui with a RUN button. Behind the button is the code

$global:results = .\powershellscript.ps1
$global:results | out-gridview


The grid displays for about 2 seconds then it and the form closes and I have no idea why ?

Thoughts ?

Thanks
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: GUI closing after script run

Post by davidc »

Please refer to this article as to why the form might be closing:

https://www.sapien.com/blog/2015/06/29/ ... e-my-form/

As for Out-GridView, you might want to use the -Wait parameter to hold the pipeline, otherwise the cmdlet will return immediately.
David
SAPIEN Technologies, Inc.
Tony67
Posts: 5
Last visit: Wed Mar 24, 2021 6:28 pm

Re: GUI closing after script run

Post by Tony67 »

Thanks - that was it !!

Much appreciated
This topic is 5 years and 7 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