473,799 Members | 3,267 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 FileSystemWatch er
- a time when the file is expected to arrive, used to set a timer

FileSystemWatch er 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 FileSystemWatch er 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 FileSystemWatch er 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 ProperTimerInte rval() As Double
Dim MyLog As New EventLog
MyLog.Source = "MyCompany"

Dim NextCheckTime As Date
If CInt(Time.Text. Substring(0, 2)) < CInt(Date.Now.H our) Then
NextCheckTime = Date.Parse(Date .Now.AddDays(1) .Date & " " &
Time.Text)
Else
NextCheckTime = Date.Parse(Date .Now.Date & " " & Time.Text)
End If
NextCheckTime = NextCheckTime.A ddHours(1)

Dim IntervalToRetur n As Double =
NextCheckTime.S ubtract(Date.No w).TotalMillise conds

If Debug.Text.ToLo wer = "true" Then
MyLog.WriteEntr y("The daily timer is set to expire in " &
IntervalToRetur n & " milliseconds, which is " & IntervalToRetur n / 1000 / 60
/ 60 & " hours.", EventLogEntryTy pe.Information)
End If

Return IntervalToRetur n
End Function
Feb 15 '06 #1
3 1934
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 FileSystemWatch er
- a time when the file is expected to arrive, used to set a timer

FileSystemWatc her 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 FileSystemWatch er 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 @ intelligentsyst emsconsulting.c om> wrote in message
news:Of******** ******@TK2MSFTN GP10.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 FileSystemWatch er
- a time when the file is expected to arrive, used to set a timer

FileSystemWatch er 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 FileSystemWatch er 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 FileSystemWatch er 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 ProperTimerInte rval() As Double
Dim MyLog As New EventLog
MyLog.Source = "MyCompany"

Dim NextCheckTime As Date
If CInt(Time.Text. Substring(0, 2)) < CInt(Date.Now.H our) Then
NextCheckTime = Date.Parse(Date .Now.AddDays(1) .Date & " " &
Time.Text)
Else
NextCheckTime = Date.Parse(Date .Now.Date & " " & Time.Text)
End If
NextCheckTime = NextCheckTime.A ddHours(1)

Dim IntervalToRetur n As Double =
NextCheckTime.S ubtract(Date.No w).TotalMillise conds

If Debug.Text.ToLo wer = "true" Then
MyLog.WriteEntr y("The daily timer is set to expire in " &
IntervalToRetur n & " milliseconds, which is " & IntervalToRetur n / 1000 /
60 / 60 & " hours.", EventLogEntryTy pe.Information)
End If

Return IntervalToRetur n
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
3115
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 colleagues noted that on her machine the launcher would complain it was missing a DLL - msvcr71.dll However, there's a very grey area concerning the redistribution of said DLL. If you've been keeping up with the dev list, and some other web
16
41638
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 issue date the experation date should automaically generate as 06/01/04. I would appreciate it if anyone could help me. Thank you Sandy
3
3254
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 world-wide Usenet newsgroup dedicated to the discussion of Microsoft Windows 64-bit programming. This is not a Call for Votes (CFV); you cannot vote at this time. Procedural details appear below. All followup discussion should be crossposted to...
5
2002
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 application which is working but it is very heavy as no proper application architecture and layering has been followed for this. It was really hard to maintain (as I was maintaing it till now) . First let me tell u a bit about my application ...
1
6528
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 Windows XP Professional. Recently I tried to install my Microsoft Visual C++.NET (2002) on the new Windows XP Professional Operating System and got the fellowing message: Microsoft Visual C++.NET Setup 1 Windows Component Update
1
1237
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 write the whole thing again as a windows app in 6 weeks. Does this sound right? Note this is for an app that isn't necessarily a good candidate for a web app. Cheers, Michael
20
383
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 clients. mmm.. Please help. Thanks, Moty.
4
9026
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 still shows on a Task Manager list. In Services it says it is still running. However there is no way to stop it other than by rebooting the whole computer. No exception (including non-CLS) is ever generated. I added a separate System.Timers.Timer...
8
1774
by: Jose | last post by:
Exists a function that determined between two dates the years,months and days? Thanks a lot.
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10243
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.