So working on a new project that will use different forms depending on what the users are trying to do. Mostly everything is working, but i have noticed when the sub forms open the first time, they have about a 5sec delayed. However, if they close it and open it up later it runs in less then a sec.
Reading online i guess its a thing with net taking longer to process the form the first time, guessing that is when it puts it it memory or something. So i guess the question is, is there a way to do a type of pre-load the other forms when the main application first gets ran.
Multi-Form load time
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.
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.
Re: Multi-Form load time
Just manually load the forms Net assembly at the beginning of your main script and the delay will likely reduce for all forms. If you are relying on other assemblies like other Windows subsystems, then load them also in the first script that executes.
I cannot think of any other thing that would low slowly the first time and faster after that. Every form is generated from a script function every time it is called.
I cannot think of any other thing that would low slowly the first time and faster after that. Every form is generated from a script function every time it is called.
-
- Posts: 24
- Last visit: Mon Feb 06, 2023 11:30 am
- Has voted: 1 time
Re: Multi-Form load time
I had this exact same situation. My childform has 15 gui elements. Long story short, have a Load and Shown function and place
[System.Windows.Forms.Application]::DoEvents() where you see fit within your Load event. I use a lot of switch statements and this resolved it for me.
Glad I'm not the only one.
[System.Windows.Forms.Application]::DoEvents() where you see fit within your Load event. I use a lot of switch statements and this resolved it for me.
Glad I'm not the only one.
Re: Multi-Form load time
So funny enough I kind of gave up on this and worked on other stuff. Then after I packaged the script as a exe, I no longer saw the delay. So it seems like the delay on opening the childforms only happen for me in the powershell Studio application when testing the applications. Once it was packaged as a exe, the delay went away.
Re: Multi-Form load time
Yes, when you only use PSS to measure loading then there is a delay when the modules are first loaded which would happen on each run. If you test in a console, then that delay won't happen. I don't think the exe makes that difference as there should be no difference in module and script load methods although the script is in memory in an EXE, so it doesn't have to be loaded from disk. Also, when you run in PSS the PSF has to be converted to a PS1 before it can be executed. This will also cause an obvious delay. I believe that, by default, the script profiler is loaded and runs to gather load statistics. This will also cause some delay.
Sorry I didn't ask you if you were running in PSS. I assumed it was just the script in a console. My mistake.
Sorry I didn't ask you if you were running in PSS. I assumed it was just the script in a console. My mistake.
Re: Multi-Form load time
Another thing I just thought of. Forms are created on demand which, in a scripted system, means they are also loaded on demand. In PSS multiform projects they would be in memory as functions, but the forms are not persistent. When you close a form, it leaves memory. To reopen a form the form is recreated. This will likely cause more delays in PSS due to the analyzer.
Note that the Sapien support is the better place to ask question about the products. They know PSS better than anyone in this forum. If you are seeing issues in PSS that are not noted as an error in the code, then post to the PSS support forum. You will get the best answers and it will provide feedback directly to Sapien. For pure coding issues then the public forums are the best place to start.
Note that the Sapien support is the better place to ask question about the products. They know PSS better than anyone in this forum. If you are seeing issues in PSS that are not noted as an error in the code, then post to the PSS support forum. You will get the best answers and it will provide feedback directly to Sapien. For pure coding issues then the public forums are the best place to start.