을 반복하지 않고 서비스 내의 모든 지정된 시간 : 나는 오후 3시 44분 15초에 대한 두 개의 입력을 가지고 왜실행 방법 나는 같은 Windows 서비스가 아래와 같이 한
Protected Overrides Sub OnStart(ByVal args() As String)
Dim timer As System.Timers.Timer = New System.Timers.Timer()
timer.Interval = 1000 '1 sec
AddHandler timer.Elapsed, AddressOf Me.OnTimer
timer.Start()
End Sub
Private Sub OnTimer(sender As Object, e As Timers.ElapsedEventArgs)
Dim Time As String = DateTime.Now.ToString("hh:mm:ss tt")
If Time = "01:58:15 PM" Or Time = "02:42:15 PM" Or Time = "02:43:15 PM" _
Or Time = "03:44:15 PM" Or Time = "06:00:15 PM" _
Or Time = "12:00:15 AM" Or Time = "05:00:15 AM" Then
Dim path As String = Application.StartupPath & "\test.log"
Dim strFile As String = String.Format(path, _
DateTime.Today.ToString("dd-MMM-yyyy"))
File.AppendAllText(strFile, String.Format("Message at-- {0}{1}", _
DateTime.Now, Environment.NewLine))
End If
End Sub
당신이 나에게 설명 할 수 있습니까? 나는 타이머 이벤트 OnTimer가 이전 OnTimer 작업이 끝날 때까지 기다렸다가 시간이 다르고 같은 시간 내에 들어 가지 않을 것이라고 생각했습니다. 뭐가 문제 야? 대한 자세한 설명
Message at-- 1/13/2015 3:44:15 PM
Message at-- 1/13/2015 3:44:15 PM
Message at-- 1/14/2015 12:00:15 AM
Message at-- 1/14/2015 5:00:15 AM
:
Private Sub OnTimer(sender As Object, e As Timers.ElapsedEventArgs)
RemoveHandler timer.Elapsed, AddressOf Me.OnTimer
Dim Time As String = DateTime.Now.ToString("hh:mm:ss tt")
If Time = "01:58:15 PM" Or Time = "02:42:15 PM" Or Time = "02:43:15 PM" _
Or Time = "03:44:15 PM" Or Time = "06:00:15 PM" _
Or Time = "12:00:15 AM" Or Time = "05:00:15 AM" Then
Dim path As String = Application.StartupPath & "\test.log"
Dim strFile As String = String.Format(path, _
DateTime.Today.ToString("dd-MMM-yyyy"))
File.AppendAllText(strFile, String.Format("Message at-- {0}{1}", _
DateTime.Now, Environment.NewLine))
End If
AddHandler timer.Elapsed, AddressOf Me.OnTimer
End Sub
OnTimer에 도달하고 해당 작업을 수행중인 경우 언급 된 작업 중에 time_elapsed 이벤트가 보류 중이거나 이미 실행중인 경우에도 time_Elapsed로 다시 이동합니까? – unknown
@unknown : 문서별로 후자입니다. 기본적으로 설정되지 않은'SynchronizingObject' 속성을 사용하지 않는 한 일반적으로 이중 이벤트를 피하려고 시도하지 않습니다. 따라서 규범은 핸들러가해야 할 필요성에 특별히주의하지 않는 한 재진입하도록 설계되어야한다는 것입니다. 내 코드에 따라 –
- 이벤트 처리기 (OnTimer)는 특정 시간에 한 번 도달 할 수 있습니까? 그리고 시간 간격은 계속 진행 중이며 이미 점유 된 경우 OnTimer로 이동하지 않습니다. 그게 내가 쓴 모든 것이 맞습니까? – unknown