Update progressbar from function?

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 2 years and 9 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
Kilsgaard
Posts: 25
Last visit: Fri Jan 26, 2024 11:37 am
Has voted: 1 time

Update progressbar from function?

Post by Kilsgaard »

Hi
I am new to the GUI development in PowerShell Studio.
I have some functions in the global section of my Forms project.
The functions is handling some webrequests and data manipulation, so I would like to update my progress bar from the functions.
But is it somehow possible to update progress bars and other fields from a function in the global section?
I cannot get it working and does not know if form controls is in scope from the global section?

hope this gives meaning :)
/Graves
by jvierra » Tue Jun 22, 2021 5:27 pm
A function is executed in the context it is called from no matter where it is stored or stated. All functions always execute in the local context and can change contexts when the function needs to do that. Usually context changes are done by execution on a new thread but global objects can represent or reference a different context from the calling context.

So, yes, the function in globals.ps1 can be used to alter a progressbar in a form or in any form. Just pass the progressbar object to the function and alter it. Now you can use the same functions to alter any prgressbar on any form.
Go to full post
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Update progressbar from function?

Post by jvierra »

A function is executed in the context it is called from no matter where it is stored or stated. All functions always execute in the local context and can change contexts when the function needs to do that. Usually context changes are done by execution on a new thread but global objects can represent or reference a different context from the calling context.

So, yes, the function in globals.ps1 can be used to alter a progressbar in a form or in any form. Just pass the progressbar object to the function and alter it. Now you can use the same functions to alter any prgressbar on any form.
This topic is 2 years and 9 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