Reputation: 121
I have a created a powershell gui application packaged as an .exe. The script calls other scripts and it informs the user through a read-only richtextbox when the called script has started and finished.
The problem is that it will only display the message indicating the start of the first script and then it will not show anything, until all the scripts have finished executing.
Here is my code:
foreach ($item in $checkedlistbox1.CheckedItems) {
$richtextbox1.AppendText("Installing " + [IO.Path]::GetFileNameWithoutExtension($item) + "...")
$richtextbox1.Update()
$path = $scriptdir+ "\" + $item + ".exe"
[System.Diagnostics.Process]::Start($path)
$Process = (Get-Process | `
Where-Object { $_.ProcessName -ieq [IO.Path]::GetFileNameWithoutExtension($item) })
$Process.WaitForExit()
$richtextbox1.AppendText("Done."+[char]13+[char]10)
$richtextbox1.Update()
}
I wonder what could be wrong here :(
Upvotes: 0
Views: 2313
Reputation: 121
Well found a dirty way to fix this:
[System.Windows.Forms.Application]::DoEvents()
Just after appending the richtextbox.
Upvotes: 1