2016-02-11 70 views
0

出於某種原因,標籤文本拒絕更新,直到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 

回答

2

這是因爲您正在指示UI線程進入睡眠狀態。如果UI線程處於睡眠狀態,則UI將不會更新。把它作爲一個規則,你永遠不會睡覺的UI線程。如果您想在做某事之前暫停兩秒鐘,請使用Timer與2000年的Interval.

+0

非常感謝您 –

相關問題