I have a form that takes a hostname as input then;
1) When user clicks check status, a function is called to check if the pc exists in AD.
2) If it does it grabs info from AD and updates relevant textboxes on form.
3) Tries to ping device using .Net object.
4) if successful displays IP, if fails displays "Ping Failed".
For some reason the textbox updates from step 2 will not execute until the results from the ping is received and ready to update it's textbox.
Why? These are separate functions.
I've tried to paste the code here but won't let me as new account and thinks it includes off-site URLs.
Check it here at PasteBin: (pastebin . com / tE0iFT5f) Remove spaces.
EDIT: Adding info requested from automated post.
Did you remember to include the following?
Product: PowerShell Studio 2015 4.2.89 64 bit
Operating system: Windows 7 Enterprise 64 bit.
How it should work:
1) User enters hostname then clicks check status.
2) Host found in AD then retrieves info and updates AD status, OU and bitlocker Key textboxes and the AD group listbox.
3) Calls ping function, updates IP Address field to "Pinging" then ping returns result to IP textbox.
What is happening:
1) User enters hostname then clicks check status.
2) Host found in AD then retrieves info but AD status, OU and bitlocker Key textboxes don't update and only the first AD group found is returned to listbox.
3) Calls ping function, doesn't update IP Address field to "Pinging".
4) App/Form freezes until failed ping returns result to IP textbox then all other textboxes and listbox updates simultaneously.
I have screenies and can provide the code but the forum is preventing me from posting either stating "Antispam: You can't have off-site URLs in your posts until you have posted a few times".
Function based form updates not executing sequentially
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.
- Technosapien
- Posts: 9
- Last visit: Wed Sep 21, 2016 4:56 am
- SAPIEN Support Forums
- Posts: 945
- Last visit: Thu Oct 22, 2015 1:10 pm
Function based form updates not executing sequentially
This is an automated post. A real person will respond soon.
Thank you for posting, Technosapien.
Here are some hints to help you get an accurate and complete answer to your question.
Ask in the best forum:
Anticipate follow-up questions!
Did you remember to include the following?
*** Make sure you do not post any licensing information ***
Thank you for posting, Technosapien.
Here are some hints to help you get an accurate and complete answer to your question.
Ask in the best forum:
- - Scripting question? For questions about Windows PowerShell or other scripting languages, use Scripting Answers.
- Software question? For questions about PowerShell Studio, PrimalScript, or other SAPIEN products, use Product Support Forums for Registered Customers.
- Trial question? For questions about trial versions of any SAPIEN product, use Trial Software Questions.
Anticipate follow-up questions!
Did you remember to include the following?
- 1. Product, version and build
2. 32 or 64 bit product
3. Operating system, e.g. Windows 7 64 bit.
4. Attach a screenshot, if applicable
5. Attach logs, crash reports, etc., in a ZIP file
*** Make sure you do not post any licensing information ***
- Technosapien
- Posts: 9
- Last visit: Wed Sep 21, 2016 4:56 am
Re: Function based form updates not executing sequentially
Bump
Is this the right forum or is there a different one for license holders
Is this the right forum or is there a different one for license holders
- Technosapien
- Posts: 9
- Last visit: Wed Sep 21, 2016 4:56 am
Re: Function based form updates not executing sequentially
My code does run. My problem is I have functions that include textbox updates. These updates included as part of my functions are not executing until all the functions finish.jvierra wrote:What is your question. You describe a lot of scenarios but fail to ask a question.
Are you saying that your code won't run?
I believe this is due to the way PowerShell Studio executes it's textbox updates.
I'm asking is this behaviour a result of how PowerShell Studio updates textboxes to try and do them all at once and if so is there a workaround for it?
Otherwise, not a product but script question, is there any obvious bug in my linked code causing this?
Thanks for your response
Re: Function based form updates not executing sequentially
I have not really looked at your code because it I not in a PFF file so it is difficult to reproduce you issue.
Windows in an event driven system. A forms cannot update controls inside of an event because the code block all other code from executing.
One what to force an update is to call "DoEvents" after updating a control.
Attached is a demo.
Also see blog posts on how to design forms and how to make forms responsive.
Windows in an event driven system. A forms cannot update controls inside of an event because the code block all other code from executing.
One what to force an update is to call "DoEvents" after updating a control.
Attached is a demo.
Also see blog posts on how to design forms and how to make forms responsive.
- Attachments
-
- Demo-ControlUpdate.psf
- Demo allowing controls to update.
- (22.52 KiB) Downloaded 196 times
Re: Function based form updates not executing sequentially
You can also just use Refresh on most controls although this will not let all forms events get handled and events in the message loop can block the refresh. "DoEvents" works under more circumstances.
Here is how to use Refresh:
Here is how to use Refresh:
PowerShell Code
Double-click the code block to select all.function WriteToTextbox { param ( [switch]$withevents ) $this.Enabled = $false $textbox1.Clear() $textbox1.Text = 'Start' 1..10 | %{ $textbox1.Lines += "$_ New line" if ($withevents) { $textbox1.Refresh() } sleep 1 } $textbox1.Lines += 'Finish' $this.Enabled = $true }
Re: Function based form updates not executing sequentially
To directly answer your concerns:
Tis has nothing to do with PowerShell Studio. The code is running in PowerShell. Run it as a PS1 file called from PowerShell and it will behave exactly the same way.Technosapien wrote:
I believe this is due to the way PowerShell Studio executes it's textbox updates.
I'm asking is this behaviour a result of how PowerShell Studio updates textboxes to try and do them all at once and if so is there a workaround for it?
Yes - it is a design and Windows understanding "bug". The code was not designed to work cooperatively with Windows. This is a common mistake with those new to scripting and scripting or programming Windows Forms. It is the event driven nature of a modern computer that you need to be aware of. There are many technical reasons for, and caveats to this. It is enough to know that, in PowerShell forms, events block execution until the event code exits.Technosapien wrote:Otherwise, not a product but script question, is there any obvious bug in my linked code causing this?
- Technosapien
- Posts: 9
- Last visit: Wed Sep 21, 2016 4:56 am
Re: Function based form updates not executing sequentially
Thanks JVierra
I'll review the code you've provided and read up more on DoEvents
I'll review the code you've provided and read up more on DoEvents