T
Trevor
This is driving us mad - please help!
Back in 2003, I coded a Windows Service in VB.NET for framework v1.1.4322.
I deployed it in Nov. 2003, and it worked fine until the end of May 2005,
when it choked (see below). We restarted it, and it worked fine for another
7 months until it choked again at the end of Dec. 2005. It has now failed
again (mid Feb. 2006). So it's failing more frequently now?
OnStart, the service reads a number of settings from the configuration file.
Among thsoe settings there is:
- a path for a FileSystemWatcher
- a time when the file is expected to arrive, used to set a timer
FileSystemWatcher is set to watch the specified path for the creation
(arrival) of a *.CSV file from another system. When it arrives, it's
contents are read and loaded into a database. In return, other data is
collected from the database and put in an output file (*.OUT). Then, a
global variable called LastExecuted is set to Now(). Declaration is at the
top of the code: Private LastExecuted As Date.
If the time value is 02:00, then we expect file arrival at 2:00AM.
Therefore, the timer is set at the proper millissecond interval between now
and the next 3:00AM that comes around (whether that's today or tomorrow,
depending on the current time). On Timer_Elapsed, I check that LastExecuted
is within the last 75 minutes. If not, the file failed to arrive today, so
make an entry in the EventLog and SmtpMail.Send an error message. Then,
re-read the configuration file (in case the expected arrival time was
changed) and then reset and restart the Timer (which typically results in a
24-hour period).
When the process chokes, this is what happens:
- the FileSystemWatcher worked as expected that day.
- the timer interval suddenly changes from 24 hours to less than a second.
Therefore, 75 minutes after the file was processed (75 minutes after
LastExecuted) several EventLog entries and e-mails are generated EVERY
SECOND.
- the process fails to update itself from the configuration file, even
though the call to that function is the next line of code to execute after
the Smtp.Send
Result: By 8AM, when people arrive for work, I get a call saying that the
server has sent them 5000+ error e-mails, and to please make it stop. I
reboot the service, and everything is fine. I even have a debug mode which
tells me what the timer calculates for its intervals and what that
transaltes into. The values are always correct. Until it's been running
for a while. Then the thing chokes.
Did something change in the framework around May 2005? Am I not doing some
necessary memory cleanup (I have Dim MyLog As New EventLog in every
function/sub - do I need to release that)? The Timer and LastExecuted ar
global variable used only once, right - there's nothing to clean up there,
is there? I don't know if this is relevant, but there is another Timer in
my code - one that starts when the FileSystemWatcher is triggered, waits 20
seconds until FTP is done transferring the file, then stops. I can't image
that interfereing - or is it? There's nothing wrong with my interval
calculation, is there?
Private Function ProperTimerInterval() As Double
Dim MyLog As New EventLog
MyLog.Source = "MyCompany"
Dim NextCheckTime As Date
If CInt(Time.Text.Substring(0, 2)) < CInt(Date.Now.Hour) Then
NextCheckTime = Date.Parse(Date.Now.AddDays(1).Date & " " &
Time.Text)
Else
NextCheckTime = Date.Parse(Date.Now.Date & " " & Time.Text)
End If
NextCheckTime = NextCheckTime.AddHours(1)
Dim IntervalToReturn As Double =
NextCheckTime.Subtract(Date.Now).TotalMilliseconds
If Debug.Text.ToLower = "true" Then
MyLog.WriteEntry("The daily timer is set to expire in " &
IntervalToReturn & " milliseconds, which is " & IntervalToReturn / 1000 / 60
/ 60 & " hours.", EventLogEntryType.Information)
End If
Return IntervalToReturn
End Function
Back in 2003, I coded a Windows Service in VB.NET for framework v1.1.4322.
I deployed it in Nov. 2003, and it worked fine until the end of May 2005,
when it choked (see below). We restarted it, and it worked fine for another
7 months until it choked again at the end of Dec. 2005. It has now failed
again (mid Feb. 2006). So it's failing more frequently now?
OnStart, the service reads a number of settings from the configuration file.
Among thsoe settings there is:
- a path for a FileSystemWatcher
- a time when the file is expected to arrive, used to set a timer
FileSystemWatcher is set to watch the specified path for the creation
(arrival) of a *.CSV file from another system. When it arrives, it's
contents are read and loaded into a database. In return, other data is
collected from the database and put in an output file (*.OUT). Then, a
global variable called LastExecuted is set to Now(). Declaration is at the
top of the code: Private LastExecuted As Date.
If the time value is 02:00, then we expect file arrival at 2:00AM.
Therefore, the timer is set at the proper millissecond interval between now
and the next 3:00AM that comes around (whether that's today or tomorrow,
depending on the current time). On Timer_Elapsed, I check that LastExecuted
is within the last 75 minutes. If not, the file failed to arrive today, so
make an entry in the EventLog and SmtpMail.Send an error message. Then,
re-read the configuration file (in case the expected arrival time was
changed) and then reset and restart the Timer (which typically results in a
24-hour period).
When the process chokes, this is what happens:
- the FileSystemWatcher worked as expected that day.
- the timer interval suddenly changes from 24 hours to less than a second.
Therefore, 75 minutes after the file was processed (75 minutes after
LastExecuted) several EventLog entries and e-mails are generated EVERY
SECOND.
- the process fails to update itself from the configuration file, even
though the call to that function is the next line of code to execute after
the Smtp.Send
Result: By 8AM, when people arrive for work, I get a call saying that the
server has sent them 5000+ error e-mails, and to please make it stop. I
reboot the service, and everything is fine. I even have a debug mode which
tells me what the timer calculates for its intervals and what that
transaltes into. The values are always correct. Until it's been running
for a while. Then the thing chokes.
Did something change in the framework around May 2005? Am I not doing some
necessary memory cleanup (I have Dim MyLog As New EventLog in every
function/sub - do I need to release that)? The Timer and LastExecuted ar
global variable used only once, right - there's nothing to clean up there,
is there? I don't know if this is relevant, but there is another Timer in
my code - one that starts when the FileSystemWatcher is triggered, waits 20
seconds until FTP is done transferring the file, then stops. I can't image
that interfereing - or is it? There's nothing wrong with my interval
calculation, is there?
Private Function ProperTimerInterval() As Double
Dim MyLog As New EventLog
MyLog.Source = "MyCompany"
Dim NextCheckTime As Date
If CInt(Time.Text.Substring(0, 2)) < CInt(Date.Now.Hour) Then
NextCheckTime = Date.Parse(Date.Now.AddDays(1).Date & " " &
Time.Text)
Else
NextCheckTime = Date.Parse(Date.Now.Date & " " & Time.Text)
End If
NextCheckTime = NextCheckTime.AddHours(1)
Dim IntervalToReturn As Double =
NextCheckTime.Subtract(Date.Now).TotalMilliseconds
If Debug.Text.ToLower = "true" Then
MyLog.WriteEntry("The daily timer is set to expire in " &
IntervalToReturn & " milliseconds, which is " & IntervalToReturn / 1000 / 60
/ 60 & " hours.", EventLogEntryType.Information)
End If
Return IntervalToReturn
End Function