473,385 Members | 1,940 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.

VB.Net Timer Issue

I have recently discovered that the system.Timers.Timer from.Net
Framework v1.1 is not reliable when used on Windows 2003 server. When
incorporated into a Windows Service, the timer_elapsed event will stop
executing after 30 to 40 days. After learning this, I found the same
issue had been documented in the the System.Threading.Timer class as
well. This limits my options for having a timer based windows service
using the .net framework.

I can convert the project to .Net Framework 2.0, but I am unsure
whether or not this will resolve the issue.

Any ideas would be helpful.

Thank you.

Dec 26 '06 #1
10 4235
Why do I think the actual problem occurs at 49.7 days. This is a known
issue with 32 bit windows (2^31-1 milliseconds is about 49.7 days). It's
not that the timer service stops, it's that the internal timers wrap back to
zero and the trigger doesn't occur anymore. The work around is to track
what day or month it is (numeric day of month or month of year is
sufficient) Here's an example workaround.

Module Module1
Public ReadOnly Interval As New System.TimeSpan(1, 0, 0)
Public t As New System.Timers.Timer(Interval.Milliseconds)
Public MonthNumber As Integer = Today.Month

Sub Main()
AddHandler t.Elapsed, AddressOf t_Elapsed
t.Start()
End Sub

Private Sub t_Elapsed(ByVal sender As Object, ByVal e As
System.Timers.ElapsedEventArgs)
If MonthNumber <Today.Month Then
RemoveHandler t.Elapsed, AddressOf t_Elapsed
MonthNumber = Today.Month
t = New System.Timers.Timer(Interval.Milliseconds)
AddHandler t.Elapsed, AddressOf t_Elapsed
t.Start()
End If

' Proceess timer event
End Sub

End Module
Mike Ober.

"igor" <jo********@yahoo.comwrote in message
news:11**********************@a3g2000cwd.googlegro ups.com...
>I have recently discovered that the system.Timers.Timer from.Net
Framework v1.1 is not reliable when used on Windows 2003 server. When
incorporated into a Windows Service, the timer_elapsed event will stop
executing after 30 to 40 days. After learning this, I found the same
issue had been documented in the the System.Threading.Timer class as
well. This limits my options for having a timer based windows service
using the .net framework.

I can convert the project to .Net Framework 2.0, but I am unsure
whether or not this will resolve the issue.

Any ideas would be helpful.

Thank you.

Dec 27 '06 #2
Michael,
Thank you for your help. I have a couple of questions. Why is it
that resetting the timer variable to a new instance every month fixes
the issue? If the System.Timers.Timer class elapsed events fire when
the internal timer reaches a specific future time value, than wouldn't
any elapsed event set to fire after the 49.7 day point fail?

As I understand it, the internal timer you mention is the timer which
starts when the server is rebooted and increments until the 49.7 day
point is reached.

Thanks again

Michael D. Ober wrote:
Why do I think the actual problem occurs at 49.7 days. This is a known
issue with 32 bit windows (2^31-1 milliseconds is about 49.7 days). It's
not that the timer service stops, it's that the internal timers wrap back to
zero and the trigger doesn't occur anymore. The work around is to track
what day or month it is (numeric day of month or month of year is
sufficient) Here's an example workaround.

Module Module1
Public ReadOnly Interval As New System.TimeSpan(1, 0, 0)
Public t As New System.Timers.Timer(Interval.Milliseconds)
Public MonthNumber As Integer = Today.Month

Sub Main()
AddHandler t.Elapsed, AddressOf t_Elapsed
t.Start()
End Sub

Private Sub t_Elapsed(ByVal sender As Object, ByVal e As
System.Timers.ElapsedEventArgs)
If MonthNumber <Today.Month Then
RemoveHandler t.Elapsed, AddressOf t_Elapsed
MonthNumber = Today.Month
t = New System.Timers.Timer(Interval.Milliseconds)
AddHandler t.Elapsed, AddressOf t_Elapsed
t.Start()
End If

' Proceess timer event
End Sub

End Module
Mike Ober.

"igor" <jo********@yahoo.comwrote in message
news:11**********************@a3g2000cwd.googlegro ups.com...
I have recently discovered that the system.Timers.Timer from.Net
Framework v1.1 is not reliable when used on Windows 2003 server. When
incorporated into a Windows Service, the timer_elapsed event will stop
executing after 30 to 40 days. After learning this, I found the same
issue had been documented in the the System.Threading.Timer class as
well. This limits my options for having a timer based windows service
using the .net framework.

I can convert the project to .Net Framework 2.0, but I am unsure
whether or not this will resolve the issue.

Any ideas would be helpful.

Thank you.
Dec 28 '06 #3
I'm guessing here on the solution as it sounds like the 32 bit millisecond
rollover. As for why the creation of a new timer - this should initialize
the timer to "0" and then it should be able to run for 49.7 days. When
windows hits 49.7 days (2^31-1) milliseconds, it simply rolls over to 0.
Windows 95 would actually become unstable at this point (if it hadn't
already done so from usage). As for your question, I don't have an answer
since for longer time periods I use the task manager to start an application
at a specific time and not application code.

Mike.

"igor" <jo********@yahoo.comwrote in message
news:11**********************@h40g2000cwb.googlegr oups.com...
Michael,
Thank you for your help. I have a couple of questions. Why is it
that resetting the timer variable to a new instance every month fixes
the issue? If the System.Timers.Timer class elapsed events fire when
the internal timer reaches a specific future time value, than wouldn't
any elapsed event set to fire after the 49.7 day point fail?

As I understand it, the internal timer you mention is the timer which
starts when the server is rebooted and increments until the 49.7 day
point is reached.

Thanks again

Michael D. Ober wrote:
>Why do I think the actual problem occurs at 49.7 days. This is a known
issue with 32 bit windows (2^31-1 milliseconds is about 49.7 days). It's
not that the timer service stops, it's that the internal timers wrap back
to
zero and the trigger doesn't occur anymore. The work around is to track
what day or month it is (numeric day of month or month of year is
sufficient) Here's an example workaround.

Module Module1
Public ReadOnly Interval As New System.TimeSpan(1, 0, 0)
Public t As New System.Timers.Timer(Interval.Milliseconds)
Public MonthNumber As Integer = Today.Month

Sub Main()
AddHandler t.Elapsed, AddressOf t_Elapsed
t.Start()
End Sub

Private Sub t_Elapsed(ByVal sender As Object, ByVal e As
System.Timers.ElapsedEventArgs)
If MonthNumber <Today.Month Then
RemoveHandler t.Elapsed, AddressOf t_Elapsed
MonthNumber = Today.Month
t = New System.Timers.Timer(Interval.Milliseconds)
AddHandler t.Elapsed, AddressOf t_Elapsed
t.Start()
End If

' Proceess timer event
End Sub

End Module
Mike Ober.

"igor" <jo********@yahoo.comwrote in message
news:11**********************@a3g2000cwd.googlegr oups.com...
>I have recently discovered that the system.Timers.Timer from.Net
Framework v1.1 is not reliable when used on Windows 2003 server. When
incorporated into a Windows Service, the timer_elapsed event will stop
executing after 30 to 40 days. After learning this, I found the same
issue had been documented in the the System.Threading.Timer class as
well. This limits my options for having a timer based windows service
using the .net framework.

I can convert the project to .Net Framework 2.0, but I am unsure
whether or not this will resolve the issue.

Any ideas would be helpful.

Thank you.

Dec 28 '06 #4
"Michael D. Ober" <obermd.@.alum.mit.edu.nospamwrote in
news:#Y**************@TK2MSFTNGP06.phx.gbl:
Why do I think the actual problem occurs at 49.7 days. This is a
known issue with 32 bit windows (2^31-1 milliseconds is about 49.7
days). It's not that the timer service stops, it's that the internal
timers wrap back to zero and the trigger doesn't occur anymore. The
work around is to track what day or month it is (numeric day of month
or month of year is sufficient) Here's an example workaround.
I recall seeing a KB article about this... do you happen to have any links
to any MS documentation?
I did find an article Joel on Software linked - Southern California's ATC
servers crashed after 49.7 days.

But I thought MS fixed this in a service pack?
Dec 28 '06 #5
"igor" <jo********@yahoo.comwrote in news:1167168930.265904.288150
@a3g2000cwd.googlegroups.com:
I have recently discovered that the system.Timers.Timer from.Net
Framework v1.1 is not reliable when used on Windows 2003 server. When
incorporated into a Windows Service, the timer_elapsed event will stop
executing after 30 to 40 days. After learning this, I found the same
issue had been documented in the the System.Threading.Timer class as
well. This limits my options for having a timer based windows service
using the .net framework.

I can convert the project to .Net Framework 2.0, but I am unsure
whether or not this will resolve the issue.

Seems like there is a hotfix:

..NET 1.1
http://support.microsoft.com/kb/843561/en-us
Dec 28 '06 #6
igor wrote:
I have recently discovered that the system.Timers.Timer from.Net
Framework v1.1 is not reliable when used on Windows 2003 server. When
incorporated into a Windows Service, the timer_elapsed event will stop
executing after 30 to 40 days. After learning this, I found the same
issue had been documented in the the System.Threading.Timer class as
well. This limits my options for having a timer based windows service
using the .net framework.
Only use the Timer to sidestep the Service's OnStart routine.
Within your "main processing" loop, use Threading.Sleep() instead, as in

Imports System.Threading

Private _bStopRequested as Boolean
Private _bStopped as Boolean

Sub OnStart()
tmrBoot.Start()
End Sub

Sub OnStop()
_bStopRequested = True
Do While Not _bStopped
Thread.Sleep(500)
Loop
End Sub

Sub tmrBoot_Timer()
tmrBoot.Stop()

Me.Run()
End Sub

Sub Run()
_Stopped = False
Do While Not bStopRequested
' Do the real work here

Thread.Sleep(1000)
Loop
_Stopped = True
End Sub

HTH,
Phill W.
Jan 2 '07 #7
No links to documentation. Just my memory that this was a problem with
Windows 95 and early versions of NT prior to one of the NT4 service packs.
As far as I know, the server crash issue was fixed in Windows 98 and 2000.
However, the underlying problem itself - 32 bit timer counters rolling over
after 49.7 days will not be resolved until the transition to 64 bit
computing is complete. Then the rollover time will be measured in
centuries.

Mike.

"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"Michael D. Ober" <obermd.@.alum.mit.edu.nospamwrote in
news:#Y**************@TK2MSFTNGP06.phx.gbl:
>Why do I think the actual problem occurs at 49.7 days. This is a
known issue with 32 bit windows (2^31-1 milliseconds is about 49.7
days). It's not that the timer service stops, it's that the internal
timers wrap back to zero and the trigger doesn't occur anymore. The
work around is to track what day or month it is (numeric day of month
or month of year is sufficient) Here's an example workaround.

I recall seeing a KB article about this... do you happen to have any links
to any MS documentation?
I did find an article Joel on Software linked - Southern California's ATC
servers crashed after 49.7 days.

But I thought MS fixed this in a service pack?

Jan 2 '07 #8
"Michael D. Ober" <obermd.@.alum.mit.edu.nospamwrote in
news:e6**************@TK2MSFTNGP02.phx.gbl:
No links to documentation. Just my memory that this was a problem
with Windows 95 and early versions of NT prior to one of the NT4
service packs. As far as I know, the server crash issue was fixed in
Windows 98 and 2000. However, the underlying problem itself - 32 bit
timer counters rolling over after 49.7 days will not be resolved until
the transition to 64 bit computing is complete. Then the rollover
time will be measured in centuries.
Here's the SP: http://support.microsoft.com/kb/843561/en-us
Jan 2 '07 #9
You would think MS would have caught this during .NET 1.1 development since
the OS teams had already addressed and fixed problems with the same
underlying tickcount rollover.

Mike.

"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"Michael D. Ober" <obermd.@.alum.mit.edu.nospamwrote in
news:e6**************@TK2MSFTNGP02.phx.gbl:
>No links to documentation. Just my memory that this was a problem
with Windows 95 and early versions of NT prior to one of the NT4
service packs. As far as I know, the server crash issue was fixed in
Windows 98 and 2000. However, the underlying problem itself - 32 bit
timer counters rolling over after 49.7 days will not be resolved until
the transition to 64 bit computing is complete. Then the rollover
time will be measured in centuries.

Here's the SP: http://support.microsoft.com/kb/843561/en-us


Jan 3 '07 #10
"Michael D. Ober" <obermd.@.alum.mit.edu.no.spamwrote in
news:15*****************@newsread1.news.pas.earthl ink.net:
You would think MS would have caught this during .NET 1.1 development
since the OS teams had already addressed and fixed problems with the
same underlying tickcount rollover.
I noticed in Microsoft's KB that .NET CF 2.0 was still affected until a
recent SP ;-)
Jan 3 '07 #11

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

Similar topics

13
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on...
3
by: ELO | last post by:
Hi all Every week, I need to get two files on a remote server. I have developped a C# Windows Service with two System.Threading.Timer to do this task For the first one, the delay (TimeSpan...
2
by: Benjamin | last post by:
Hi, I am having a problem enabling a timer in my class. I have attached some sample pseudo code (see "Sample code illustrating issue") so you can see what I am talking about. Whats the issue?...
5
by: Dhilip Kumar | last post by:
Hi all, I have developed a windows service using the windows service project template in VS.NET. I have used three controls in the service, a timer, performance counter and a message queue...
8
by: Stephen Rice | last post by:
Hi, I have a periodic problem which I am having a real time trying to sort. Background: An MDI VB app with a DB on SQL 2000. I have wrapped all the DB access into an object which spawns a...
4
by: Daniel | last post by:
Hey guys Here is what i want to do. I have made a multiplayer game that needs to when more than one player is ready start a countdown that the clients can see, so players can still join in this...
7
by: RobKinney1 | last post by:
Hello, Wow...I have one for you all and hopefully I am not understanding this timer object correctly. I have a timer setup that pulses a connection through a socket every 60 seconds. But it...
3
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
I am trying to use the timer to make a login form show after a specified interval. However, if the interval is set to a value greater than 5000 nanosecond, then it does not respond. What could be...
8
by: Ollie Riches | last post by:
I'm looking into a production issue related to a windows service and System.Timers.Timer. The background is the windows service uses a System.Timers.Timer to periodically poll a directory location...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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...

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.