|
Public Class Class1
' *****************************************************
' オブジェクト作成
' *****************************************************
Private Shared myTimer As New System.Windows.Forms.Timer()
Private Shared alarmCounter As Integer = 1
Private Shared exitFlag As Boolean = False
' *****************************************************
' タイマー用イベント
' *****************************************************
Private Shared Sub TimerEventProcessor(myObject As Object, _
myEventArgs As EventArgs)
' タイマーイベント内では再入を防ぐためにタイマーを停止
myTimer.Stop()
' このメッセージの応答によって、タイマー処理を継続かキャンセル
' するかが決まる
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()
' *****************************************************
' イベントの登録
' *****************************************************
AddHandler myTimer.Tick, AddressOf TimerEventProcessor
' 5秒毎のタイマー
myTimer.Interval = 5000
' タイマー開始
myTimer.Start()
' タイマーを受けれるようにループ処理を行う
' タイマーが完全に完了するまで、ループする
' タイマー内でタイマーをキャンセルするとループが終了
While exitFlag = False
' Processes all the events in the queue.
Application.DoEvents()
End While
End Sub
End Class
| |