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.
Locked
Tony67
Posts: 2
Joined: Thu Sep 06, 2018 1:20 pm

GUI closing after script run

Post by Tony67 » Thu Sep 06, 2018 1:28 pm

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: 5801
Joined: Thu Aug 18, 2011 4:56 am

Re: GUI closing after script run

Post by davidc » Thu Sep 06, 2018 1:43 pm

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: 2
Joined: Thu Sep 06, 2018 1:20 pm

Re: GUI closing after script run

Post by Tony67 » Thu Sep 06, 2018 2:43 pm

Thanks - that was it !!

Much appreciated

Locked