Load Form before executing code in the script

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
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.
User avatar
Posts: 55
Last visit: Thu Apr 22, 2021 6:09 am

Load Form before executing code in the script

Post by rubberduck »

Product: PowerShell Studio 2020 (64 Bit)
Build: v5.7.172
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.18363.0
PowerShell version(s): 5.1.18362

I keep noticing that the code inside a graphical application is executed before the application window is displayed.

In my particular case I want to display computer information in a new (child) window.
The logic of the background job that gets these information is in the child form.
When I try to open the childform from the mainform, i would expect the childform to open and then
start the job. But the behaviour seems to be different here, the job executes instantly and slows down the opening of
the child form as long as the background job is done.

I probably just lack the programming background here, that's why I'm asking the pros.
Thank you very much for your help.

Please see attached picture.
GH Toolbox Version 1.0 2021-04-22 13.18.10.png
GH Toolbox Version 1.0 2021-04-22 13.18.10.png (58.25 KiB) Viewed 1287 times
Form 2021-04-22 13.19.16.png
Form 2021-04-22 13.19.16.png (24.52 KiB) Viewed 1287 times

User avatar
Site Admin
Posts: 755
Last visit: Thu May 13, 2021 12:57 pm
Answers: 14
Been upvoted: 11 times

Re: Load Form before executing code in the script

Post by brittneyr »

Without seeing any code, I can only make guesses. If you want code to happen at a specific time, please make sure all code is an an event handler. In your case, starting your job after the form is loaded might be a good idea if its affecting performance. In the childform, try starting the job in the Shown event as this event is only raised the first time a form is displayed.
Brittney Ryn
SAPIEN Technologies, Inc.