Page 1 of 1

async update GUI text

Posted: Sun Nov 04, 2018 6:55 pm
by sctsprin
Hi, I've borrowed this powershell studio form code from the forum to run a background task then display the result in a textbox,
However the textbox flashes the result, I would like the result to remain until the next updated value is displayed,
Could someone please help?

Windows 10, Powershell studio 2018, v5.5.155

thanks
james

Re: async update GUI text

Posted: Sun Nov 04, 2018 7:08 pm
by jvierra
Change this line:
$textbox1.Text = $results

To this:
$textbox1.Text += $results

Re: async update GUI text

Posted: Sun Nov 04, 2018 10:39 pm
by sctsprin
Thanks for the reply, but that ends up just adding to the last result, so i end up with "12345...." etc
I want to only see the current text result displayed until it's replaced by the new result, so "1" is displayed until it's replaced by "2" etc.

Re: async update GUI text

Posted: Sun Nov 04, 2018 10:46 pm
by jvierra
If the updates happen too fast then it will always look funny.

What is the purpose of just outputting numbers as fast as you can?

Code: Select all

		Param ($Job)
		if($results = Receive-Job -Job $Job | Select-Object -Last 1){
		    $textbox1.Text = $results
        }

Re: async update GUI text

Posted: Mon Nov 05, 2018 3:12 am
by sctsprin
I actually just want to refresh once a minute, but need the last result to display until the next update, which currently isn’t happening, instead it’s flashing for a split second and is then empty u til the next flash update

Re: async update GUI text

Posted: Mon Nov 05, 2018 3:27 am
by jvierra
The code I posted does exactly that you just need to set the timer to the value you want.

Re: async update GUI text

Posted: Mon Nov 05, 2018 6:34 pm
by sctsprin
thanks, i found my mistake, i removed the if statement surrounding the textbox1.text = $results, which caused empty data to be displayed

thanks
james

Re: async update GUI text

Posted: Mon Nov 05, 2018 6:52 pm
by jvierra
That is not what is happening. The "if statement prevents a null value from being assigned to the text which was the initial issue with your code. Displaying once a second comes when the sleep is set to 60 seconds and not 1000 milliseconds.