473,385 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Windows Services works for years/months/weeks, then chokes

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
Feb 15 '06 #1
3 1919
This sounds like a very complex app - and sounds nicely done. The
difficulty with something like this is that you are relying on an
outside source to provide a file. Scroll down.

Trevor wrote:
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).

How often does the file not arrive as expected? Is the expected arrival
time always modified? If it is not modified, what is the result within
the application? Does it affect the time_interval?
This may be a shot in the dark, but it's all I can think of.

Tom
Feb 15 '06 #2
You say that once the FileSystemWatcher is triggered, you wait another 20
seconds until FTP finishes transferring the file.

The types of things I would be looking at include:

- How do you determine if the inwards FTP operation has completed?

- What size is a 'normal' or inward file and how long does it normally
take to
transfer?

- What should happen if the inwards transfer does not complete within
20 seconds?

- On the days it 'choked' was the transferred file significantly larger
than normal?

- On the days it 'choked' what does the FTP log show?

I get the impression that this is file that normally arrives sometime during
the early hours of the morning and is processed ready for the day ahead. If
this is the case then what is the latest time the file could arrive before
one could assume that is not going to arrive today and how long does the
processing of the file take? Also, is it a requirement that the processing
of the file is finished before a certain time?

If the latest time for arrival was within a relatively short time of the
normal arrival time (say up to 1 hour of 2:00 AM) and the processing time
was relatively short (say 1 hour at the most) I would be inclined to use
task scheduler rather than a service. With the job scheduled for say 4:00 AM
it would be all over by 5:00 AM.
The job would simply check to see if the file exists, process it if it does
and report appropriately if it doesn't.
"Trevor" <tsides @ intelligentsystemsconsulting.com> wrote in message
news:Of**************@TK2MSFTNGP10.phx.gbl...
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

Feb 16 '06 #3
My guess is that you have an overflow error in a variable used in the
timer. WinNT used to have a bug where it would crash after running for
something like a week. MS used an integer to track the number of
seconds since the last reboot and it would overflow in about a week. If
you have something that tracks the milliseconds since startup, you may
be facing a similar issue.

Feb 16 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

35
by: Michael Kearns | last post by:
I've been using python to write a simple 'launcher' for one of our Java applications for quite a while now. I recently updated it to use python 2.4, and all seemed well. Today, one of my...
16
by: sandy | last post by:
Hi, Using Java script I am trying to create code where when you place in the start date it automatically calculates 6 months for the experations date. For example when I place 01/01/04 as the...
3
by: Christian McArdle | last post by:
REQUEST FOR DISCUSSION (RFD) unmoderated group comp.os.ms-windows.programmer.64bit This is a formal Request For Discussion (RFD) to create comp.os.ms-windows.programmer.64bit as an unmoderated...
5
by: Rajat Tandon | last post by:
Hello Everybody, Please guide me so that I can fulfill this challenging assisnment ... I have been asked to "Restructure a Windows application" from scratch in 2 months. The existing...
1
by: Scott Chang | last post by:
Hi all, 1)I used Microsoft Visual C++.NET (2002) on my Windows Me and Windows XP Home Edition for the last one and half years. 4-5 weeks ago, I upgraded my PC from Windows XP Home Edition to...
1
by: Michael C | last post by:
Someone at work told me that he has estimated it is taking him 5 to 10 times longer to write an app as a web app instead of windows app. He's been working on it for 18 months and reckons he could...
20
by: Moty Michaely | last post by:
Hello, Can anyone please help me finding a good way to develop a c# winforms application client for a pre-developed windows service? Should I use wse2 with tcp protocol? Bu I still have win98...
4
by: Kris | last post by:
I have a Windows Service in C# talking to a serial port and using Remoting. It also uses several COM objects. On customer's computer the service will occassionally hang somewhere - the service...
8
by: Jose | last post by:
Exists a function that determined between two dates the years,months and days? Thanks a lot.
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.