3. DoEvents(保证消息循环)
可以使用一循环执行定时。代码示例:
Public Shared Sub Sleep(ByVal Interval)
Dim __time As DateTime = DateTime.Now
Dim __Span As Int64 = Interval * 10000 '因为时间是以100纳秒为单位。
While (DateTime.Now.Ticks - __time.Ticks < __Span)
Application.DoEvents()
End While
End Sub
'按一下按钮,label上出现"0",过了5秒后,出现"1"
Dim WithEvents x As Timer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Label1.Text = "0"
x = New Timer()
x.Interval = 5000
x.Enabled() = True
End Sub
Private Sub x_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles x.Tick
Label1.Text = "1"
End Sub