2016-10-13 64 views

回答

0

嘗試使用System.Timers.TimerRandom類:

如果您使用的是Windows Forms,這非常簡單。使用Timer控件和每個隨機化幾毫秒:

Dim sec as Decimal 
Dim targetSeconds as Integer = 5 
Dim rnd as New Random() 

'Omitting the parameters of the event 
Private Sub timer_tick() Handles Timer.Tick 
    sec = sec + Timer.Interval 
    Label.Text = rnd.Next() 
    If sec >= targetSeconds Then 
     Timer.Stop() 
    End If 
End Sub 

如果您在控制檯應用程序,但是,你要一個變量指定爲System.Timers.Timer,添加Tick事件處理程序,並使用相同的代碼如上。請務必致電Start()啓動計時器