Open form window and run process without user interaction

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 7 years and 2 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
MikePro85
Posts: 3
Last visit: Fri May 26, 2023 10:43 am

Open form window and run process without user interaction

Post by MikePro85 »

I'm having difficulties to figure out how to make the following happen.

Open up a form window and let a process run in the background without a user having to do any interaction (such as clicking a button).

1. Example:
When the program is started by the user, the program takes some time to load before the window comes up where there is interaction with the user. Now, how can I get a progress bar running during the loading time of the program?

2. Example:
The user has made an selection of programs he wants to install out a pool (e.g. 7-zip, MS Office, VLC-Player). He hits the 'install' button, I need a new window to open with a progress bar and a text saying, what currently is being installed. The important thing about it is - and my challenge - the window has to open and run the process through without user interaction (such as clicking a button in that window) and at the end of all applications the form should close itself.

Whatever I do - the program runs through completely without opening a window when I have it close at the end - or when I don't ask it to close at the end - it will run everything before opening the window. But that's not what I need. I need the window to open and then the script / processes to run.

Does anyone know how to do that?

Mike
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Open form window and run process without user interaction

Post by jvierra »

#1 - You can't. You cannot display anything while the form is loading.
#2 - It is very difficult to manage installers. They do not persist as a process while they run.

Start here to learn how to use forms effectively: https://www.sapien.com/blog/2012/05/16/ ... ive-forms/

YOu should not run any time consuming code in the load event. You can place it in the $Form1_Shown={...} event and it will run after the form is displayed. You should not place long running code in any event or the form will freeze until the process is finished. The link above shows the way to avoid that for large, long running scripts.
  1. $form1_Shown={
  2.     # code here only runs after the form is displayed
  3. }
This topic is 7 years and 2 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