G
Guest
Hi,
I made a Windows Service in VS.Net 2003 with VB. I've included the main
code, there's some other code, but it's rem'ed out and essentially just a
timer running here. I'm trying to run something at 5:20 every day. I caught
a comment in a different thread about system.threads.timer perhaps being a
better way of handling the situation, but anyway...
When I start the service, I see that the memory usage in Task Manager is
7,124. In 30 minutes it's 7,232. 15 hours later it's 7,640 K. It's
leveling off, but I guess I am wondering why it's getting larger at all.
Perhaps a second question (related), is if this is the best way to run
something at a specific time.
Dim timerClean As New System.Timers.Timer
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
boolAlreadyRan = True
dateRunTime = TimeValue("5:20:00 pm")
' Set the timer to check every 5 minutes.
StartTimer(timerClean, 300000)
EventLog1.WriteEntry("In OnStart")
End Sub 'OnStart
Private Sub StartTimer(ByRef aTimer As System.Timers.Timer, ByVal
Interval As Integer)
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
aTimer.Interval = Interval
aTimer.Enabled = True
End Sub
Private Sub StopTimer(ByRef aTimer As System.Timers.Timer)
aTimer.Enabled = False
End Sub
Private Sub OnTimedEvent(ByVal source As Object, ByVal e As
ElapsedEventArgs)
If (boolAlreadyRan = False) And (TimeValue(Now) > dateRunTime) Then
'Timer Event Occurred.
boolAlreadyRan = True
End If
If (boolAlreadyRan = True) And (TimeValue(Now) > dateRunTime) And
(TimeValue(Now) < dateRunTime.AddMinutes(6)) Then
boolAlreadyRan = False
End If
End Sub 'OnTimedEvent
I made a Windows Service in VS.Net 2003 with VB. I've included the main
code, there's some other code, but it's rem'ed out and essentially just a
timer running here. I'm trying to run something at 5:20 every day. I caught
a comment in a different thread about system.threads.timer perhaps being a
better way of handling the situation, but anyway...
When I start the service, I see that the memory usage in Task Manager is
7,124. In 30 minutes it's 7,232. 15 hours later it's 7,640 K. It's
leveling off, but I guess I am wondering why it's getting larger at all.
Perhaps a second question (related), is if this is the best way to run
something at a specific time.
Dim timerClean As New System.Timers.Timer
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
boolAlreadyRan = True
dateRunTime = TimeValue("5:20:00 pm")
' Set the timer to check every 5 minutes.
StartTimer(timerClean, 300000)
EventLog1.WriteEntry("In OnStart")
End Sub 'OnStart
Private Sub StartTimer(ByRef aTimer As System.Timers.Timer, ByVal
Interval As Integer)
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
aTimer.Interval = Interval
aTimer.Enabled = True
End Sub
Private Sub StopTimer(ByRef aTimer As System.Timers.Timer)
aTimer.Enabled = False
End Sub
Private Sub OnTimedEvent(ByVal source As Object, ByVal e As
ElapsedEventArgs)
If (boolAlreadyRan = False) And (TimeValue(Now) > dateRunTime) Then
'Timer Event Occurred.
boolAlreadyRan = True
End If
If (boolAlreadyRan = True) And (TimeValue(Now) > dateRunTime) And
(TimeValue(Now) < dateRunTime.AddMinutes(6)) Then
boolAlreadyRan = False
End If
End Sub 'OnTimedEvent