I am trying to make a label that changes every second for an event. What I currently have makes the thread sleep all the way through from “Rock” to “Shoot” and skips the “Paper” and “Scissors”. Does anyone have any ideas as to what I should do to properly display the label so that they are all displayed in equal time increments? Any help would be much appreciated.
lblCountdown.Text = "Rock"
System.Threading.Thread.Sleep(1000)
lblCountdown.Text = "Paper"
System.Threading.Thread.Sleep(1000)
lblCountdown.Text = "Scissors"
System.Threading.Thread.Sleep(1000)
lblCountdown.Text = "Shoot!"
If you’re calling it from the UI thread, the rendering will lock up until the code is finished, so you won’t see Paper or Scissors. One solution (not the best solution, but a solution) is to call
Me.Refresh()orApplication.DoEvents()before eachSleep. This will tell the UI to redraw itself.A better solution would be to use some kind of timer that ticks at a 1 second interval, which would operate in another thread, freeing up your UI thread for more important things.