2011-01-05 1 views

답변

4

Timer 클래스를 확인하십시오.

Public Class Form1 
    Private T As Timer 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
     T = New Timer() 
     AddHandler T.Tick, AddressOf TimerTicker 
     T.Interval = (1000 * 3) 'Every 3 seonds 
     T.Start() 
    End Sub 
    Private Sub TimerTicker(ByVal sender As Object, ByVal ev As EventArgs) 
     Trace.WriteLine("here") 
    End Sub 
End Class 
+0

감사합니다. 그것은 작동합니다. – Voldemort

0

특정 시간 간격으로 기능을 실행하는 것에 대해 이야기하고 있습니까? 그렇다면 타이머 컨트롤이 작동합니다. Google search은 Timer에 대한 많은 자습서를 제공합니다.

0

어떻습니까? 은 타이머를 사용하고이며 MessageBox 경고에 원하는 모든 방법으로 대체하십시오.

다음 예

알람을 5 초를 설정하는 간단한 간격 타이머를 구현합니다. 알람이 발생하면 MessageBox는 알람이 시작된 횟수를 표시하고 사용자가 타이머를 계속 실행해야하는지 여부를 묻는 메시지를 표시합니다.

당신은 자세한 내용 here을 찾을 수 있습니다.

Public Class Class1 
>  Private Shared WithEvents myTimer As New System.Windows.Forms.Timer() 
>  Private Shared alarmCounter As Integer = 1 
>  Private Shared exitFlag As Boolean = False  

> 
>  ' This is the method to run when the timer is raised. 
>  Private Shared Sub TimerEventProcessor(myObject As 
> Object, _ 
>           ByVal myEventArgs As EventArgs) _ 
>          Handles myTimer.Tick 
>   myTimer.Stop() 
> 
>   ' Displays a message box asking whether to continue running the 
> timer. 
>   If MessageBox.Show("Continue running?", "Count is: " & 
> alarmCounter, _ 
>        MessageBoxButtons.YesNo) = 
> DialogResult.Yes Then 
>    ' Restarts the timer and increments the counter. 
>    alarmCounter += 1 
>    myTimer.Enabled = True 
>   Else 
>    ' Stops the timer. 
>    exitFlag = True 
>   End If 
>  End Sub 
> 
>  Public Shared Sub Main() 
>   ' Adds the event and the event handler for the method that will 
>   ' process the timer event to the timer. 
> 
>   ' Sets the timer interval to 5 seconds. 
>   myTimer.Interval = 5000 
>   myTimer.Start() 
> 
>   ' Runs the timer, and raises the event. 
>   While exitFlag = False 
>    ' Processes all the events in the queue. 
>    Application.DoEvents() 
>   End While 
> 
>  End Sub  
> 
> End Class