Page 1 of 1

Run code after gui is loaded

Posted: Thu Jun 17, 2021 6:42 am
by GHIsolierung
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 refer here to my own entry:
viewtopic.php?p=80198#p80198

The task is simple:
I want to execute code, or call a function, or run a job AFTER a GUI has been loaded.
So in other words, I want my GUI to be there first and THEN perform any actions.
Plain and simple.

To do this, I create a new GUI project, create a job that collects data, and display that collected data in the GUI in a text field.
But what happens now is that the job is always executed first and the GUI starts only then, which leads to a considerable startup delay.

How can I change this behavior.

thanks for your help in advance.
Thomas

The relevant code is:
Code.txt
(2.57 KiB) Downloaded 114 times

Re: Run code after gui is loaded

Posted: Thu Jun 17, 2021 7:05 am
by brittneyr
[Topic moved by moderator to PowerShell GUIs forum]

Re: Run code after gui is loaded

Posted: Thu Jun 17, 2021 11:18 am
by jvierra
See the following articles:

https://info.sapien.com/index.php/guis/ ... sive-loops
https://info.sapien.com/index.php/guis/ ... sive-forms

There are many articlkes on that page that you will need to review to learn how to work with WinForms and PowerShell.

Re: Run code after gui is loaded

Posted: Thu Jun 17, 2021 2:28 pm
by GHIsolierung
Thanks for your reply, those are both sites I know.
However, that is not my real problem.
I want to display a GUI - wait 2 seconds after that if I want - and then I want to perform some action.
With the pages you showed me, I would have a gui that I can 'move' in the meantime of the job, but it doesn't fix my problem with the order.

Re: Run code after gui is loaded

Posted: Thu Jun 17, 2021 2:46 pm
by Alexander Riedel
https://docs.microsoft.com/en-us/dotnet ... ew=net-5.0

That would be the Form.Shown event. The Microsoft website https://docs.microsoft.com/en-us/dotnet ... esktop-4.8
has a brief explanation and order of Windows Forms events.

A google search for <windows forms events> produces additional examples and documentation.

Re: Run code after gui is loaded

Posted: Thu Jun 17, 2021 3:17 pm
by GHIsolierung
To be honest, I don't feel like watching all the documentaries.
I am not a programmer anyway and never want to become one.
That's why I go to professionals and pay licenses for support. ;)

Would it be possible, you could give me a possible solution based on the code I provided?
Thank you very much.

Re: Run code after gui is loaded

Posted: Thu Jun 17, 2021 3:53 pm
by jvierra
Sorry but this is not product support. There are other forums for product support. ALso note that basic programming and reading instructions are not part of any support for any product.

The links are not videos they are explanations and instructions on how to proceed to do what you ask. Why should I write the whiole thing all over when someone did such a good job or that already?

The instructions are short and can be read in less than ten minutes.

A simple hiont is to use a timer or use thee forn "Shown" event. That won't necessarily do what you ask so the whole of possibilites are described in the two articles.

Re: Run code after gui is loaded

Posted: Thu Jun 17, 2021 4:10 pm
by Alexander Riedel
The product purchase includes product support. It does not mean we will be writing the code for you.
Kind of like asking Microsoft do write your essay because you have an Office license :D

Go read the articles, they don't bite and it feels good to accomplish something.