为什么标签文本不会更新?

时间:2016-02-11 03:26:16

标签: vb.net

由于某种原因,标签文本拒绝更新,直到ComputerTurn()子。有谁知道为什么会这样做?

Sub PlayerTurn(ByVal no As Integer)
    pile -= no
    lblDisplay.Text = "There are " + pile.ToString + " Stones in the Pile"
    If pile = 0 Then
        EndGame("Computer")
    End If
    Threading.Thread.Sleep(2000)
    ComputerTurn()
End Sub

Sub ComputerTurn()
    Dim stones As Integer = 0
    Do
        stones = RndInt(1, 3)
    Loop While Not CheckNo(stones)
    pile -= stones
    lblCompDisplay.Text = "Computer took " + pile.ToString + " Stones"
    If pile = 0 Then
        EndGame("Player")
    Else
        btnGo.Enabled = True
    End If
End Sub

1 个答案:

答案 0 :(得分:2)

那是因为您正在指示UI线程休眠。如果UI线程处于睡眠状态,则UI不会更新。以此为例,您永远不会睡觉UI线程。如果您想在做某事之前暂停两秒钟,请使用Timer,其Interval为2000。

相关问题