简体   繁体   中英

Powershell GUI & loop pauses

What I want: my script/program(?) To do stuff on button press then wait if conditions are meet and display how long is left.

Whats happening: When I use 'Start-Sleep' it pauses the GUI and doesn't display how long is left until the very end when it displays all of the text at once.

I've attempted to look for something online and came up dry. I've attempted for, while, and do-until loops all act the same way. So I'm hoping there is another way to pause a loop.

This is basically the script I'm using:

$btn.add_click ({
    Foreach ($_ in $stuff)
    {
        #do stuff
        If ($x -eq $y)
        {
            $n = 30
            While ($n -gt 0)
            {
                $textbox.text += "$n seconds left`n"
                ###WAIT 1-5 SECOND(s)###
                $n --
            }
        }
    }
})

Here is a very comprehensive tutorial by @FoxDeploy that helps you build your WPF GUI in a way that allows commands to be triggered from the UI without freezing it.

I don't share any code here because there is really too much of it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM