473,581 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Timers.T imer.Elapsed event not firing

I have a windows application written using VB .NET that encompasses a
countdown timer modal dialog. The timer is a System.Timers.T imer with
an interval of 1 second. AutoReset is not set so accepts the default of
True. The Elapsed event handler updates the dialog box with how long
before it will close, acting as a timer itself. The dialog has a time
to close property which is checked every time the Elapsed event fires.

The problem I have is that this application has been working
successfully for well over a year. I am now in the process of moving it
to a new faster server and I am now getting an intermittent error. The
dialog timer is set for 1 minute intervals and therefore the Elapsed
event should fire 60 times, however after the application has been
running for an indeterminate time, the timer will only fire once.
Nowhere am I setting the AutoReset property to False.

I guess that the problem is with the new machine but I don't know where
to start and can't find anybody else who has had a similar problem.

Here is the dialog class.

Imports System.windows. forms

Namespace WinForms
Public Class dlgZTimer

'************** *************** *************** *************** *************** ****
'
' Displays a timer dialog
'
' Modification Log
' =============== =
'
' 16.12.2003 mike Replace system.windows. forms.timer with
system.timers.t imer
' forms timer has a bug which causes high cpu
usage
'

'************** *************** *************** *************** *************** ****
Inherits System.Windows. Forms.Form

Public TimerTitle As String
Public TimerIntervalSe cs As Long
Public TargetTimeInter valMins As Double
Public TargetTime As Date

Private nSecs As Long
Private nMins As Long
Private nHours As Long

Dim WithEvents Timer1 As System.Timers.T imer
#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeCompo nent()

'Add any initialization after the InitializeCompo nent()
call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Disp ose()
End If
End If
MyBase.Dispose( disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.Componen tModel.IContain er

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents butRunNow As System.Windows. Forms.Button
Friend WithEvents butCancel As System.Windows. Forms.Button
Friend WithEvents txtRemaining As System.Windows. Forms.TextBox
Friend WithEvents ZShadowTitle1 As Fehon.WinForms. ZShadowTitle
Friend WithEvents ToolTip1 As System.Windows. Forms.ToolTip

<System.Diagnos tics.DebuggerSt epThrough()> Private Sub
InitializeCompo nent()
Me.components = New System.Componen tModel.Containe r
Me.butRunNow = New System.Windows. Forms.Button
Me.butCancel = New System.Windows. Forms.Button
Me.txtRemaining = New System.Windows. Forms.TextBox
Me.ZShadowTitle 1 = New Fehon.WinForms. ZShadowTitle
Me.ToolTip1 = New
System.Windows. Forms.ToolTip(M e.components)
Me.SuspendLayou t()
'
'butRunNow
'
Me.butRunNow.Lo cation = New System.Drawing. Point(217, 76)
Me.butRunNow.Na me = "butRunNow"
Me.butRunNow.Ta bIndex = 0
Me.butRunNow.Te xt = "Run Now"
Me.ToolTip1.Set ToolTip(Me.butR unNow, "Stop the timer and
run the process now")
'
'butCancel
'
Me.butCancel.Lo cation = New System.Drawing. Point(217, 110)
Me.butCancel.Na me = "butCancel"
Me.butCancel.Ta bIndex = 1
Me.butCancel.Te xt = "Cancel"
Me.ToolTip1.Set ToolTip(Me.butC ancel, "Cancel the Timer")
'
'txtRemaining
'
Me.txtRemaining .Enabled = False
Me.txtRemaining .Font = New System.Drawing. Font("Microsoft
Sans Serif", 15.75!, System.Drawing. FontStyle.Regul ar,
System.Drawing. GraphicsUnit.Po int, CType(0, Byte))
Me.txtRemaining .Location = New System.Drawing. Point(179, 8)
Me.txtRemaining .Name = "txtRemaini ng"
Me.txtRemaining .Size = New System.Drawing. Size(113, 35)
Me.txtRemaining .TabIndex = 2
Me.txtRemaining .Text = "hh:mm:ss"
'
'ZShadowTitle1
'
Me.ZShadowTitle 1.BackColor =
System.Drawing. SystemColors.Co ntrol
Me.ZShadowTitle 1.CausesValidat ion = False
Me.ZShadowTitle 1.Location = New System.Drawing. Point(4, 8)
Me.ZShadowTitle 1.Name = "ZShadowTit le1"
Me.ZShadowTitle 1.ShadowTitle = "Waiting until Sunday
23-Mar-2002 10:00:00 AM"
Me.ZShadowTitle 1.Size = New System.Drawing. Size(172, 136)
Me.ZShadowTitle 1.TabIndex = 3
'
'dlgZTimer
'
Me.AutoScaleBas eSize = New System.Drawing. Size(5, 13)
Me.ClientSize = New System.Drawing. Size(298, 151)
Me.Controls.Add (Me.ZShadowTitl e1)
Me.Controls.Add (Me.txtRemainin g)
Me.Controls.Add (Me.butCancel)
Me.Controls.Add (Me.butRunNow)
Me.FormBorderSt yle =
System.Windows. Forms.FormBorde rStyle.FixedDia log
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "dlgZTimer"
Me.ShowInTaskba r = False
Me.StartPositio n =
System.Windows. Forms.FormStart Position.Center Parent
Me.Text = "Timer"
Me.ResumeLayout (False)

End Sub

#End Region

Private Sub butCancel_Click (ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles butCancel.Click
Me.Cursor = Cursors.Default
Me.DialogResult = DialogResult.Ca ncel
Me.Close()
End Sub

Private Sub butRunNow_Click (ByVal sender As System.Object,
ByVal e As System.EventArg s) Handles butRunNow.Click
Me.Cursor = Cursors.Default
Me.DialogResult = DialogResult.OK
Me.Close()
End Sub

Private Sub dlgZTimer_Load( ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load

If TimerTitle <> "" Then
Me.Text = TimerTitle
End If

' Default Timer Interval is 1 second
Timer1 = New System.Timers.T imer
Timer1.Interval = 1 * 1000
If TimerIntervalSe cs <> 0 Then
Timer1.Interval = CInt(TimerInter valSecs * 1000)
End If

' Add minutes to get target time
If TargetTimeInter valMins <> 0 Then
nSecs = CInt(TargetTime IntervalMins * 60)
TargetTime = DateAdd("s", nSecs, Date.Now)
End If

UpdateDisplay()
Me.Cursor = Cursors.WaitCur sor
Timer1.Start()

End Sub

Private Sub Timer1_Elapsed( ByVal sender As Object, ByVal e As
System.Timers.E lapsedEventArgs ) Handles Timer1.Elapsed

UpdateDisplay()
If Date.Now > TargetTime Then
Me.DialogResult = DialogResult.OK
Me.Close()
End If

End Sub

Private Sub UpdateDisplay()
ZShadowTitle1.S hadowTitle = "Waiting until " &
Format(TargetTi me, "dddd dd-MMM-yyyy hh:mm:ss tt")

nSecs = DateDiff("s", Date.Now, TargetTime)
nMins = CLng(Int(CSng(n Secs / 60)))
nHours = CLng(Int(CSng(n Mins / 60)))
nSecs = nSecs Mod 60
nMins = nMins Mod 60
txtRemaining.Te xt = Format(nHours, "00") & ":" &
Format(nMins, "00") & ":" & Format(nSecs, "00")
End Sub

End Class
End Namespace

Apr 11 '06 #1
4 11102
Hi Reds fan,

What bug of the Forms Timer are you talking about in your code. In my idea
is that the smoothest Timer, however only if you use it in a windows form.

(And don't forget to disable it in the begin of its event and to start it
again in the end of that).

Cor
Apr 11 '06 #2
Hi Cor,

I am not using the forms timer. I am using System.Timers.T imer.
The problem I have, is that intermittently it will only fire once. I've
read somewhere that you can't use it in a windows service, but this a
windows application. Is this a bug?

Chris.

Apr 11 '06 #3
Liverpool fan,

I don't know, however despite what I have read as probably you did as well,
do I use the form timer if possible, it is much easier and I did not see
problems with that yet. Therefore was my question meant as. Why don't you
try that one?

Cor

"Liverpool fan" <ch*********@fe ltex.com> schreef in bericht
news:11******** **************@ i40g2000cwc.goo glegroups.com.. .
Hi Cor,

I am not using the forms timer. I am using System.Timers.T imer.
The problem I have, is that intermittently it will only fire once. I've
read somewhere that you can't use it in a windows service, but this a
windows application. Is this a bug?

Chris.

Apr 12 '06 #4
Cor,

As you will see from the change history on the code I've posted, we've
had problems with the Forms timer in the past. I've resorted to using
the Thread Timer instead. 3rd time lucky I hope. It's less intuitive
than the other 2 but seems to work okay, so far.

Chris.

Apr 12 '06 #5

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

Similar topics

3
16860
by: Peter Johnsson | last post by:
How come the eventhandler for the timer's elapsed time event is called over and over again, even though the AutoReset property is set to false, if you assign a new value to the timer objects interval property inside the event handler? Example follows: Constructor: mTimer = new System.Timers.Timer(20000); mTimer.AutoReset = false;
10
2690
by: WhiteSocksGuy | last post by:
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a System.Timers.Timer to work for me to display a splash screen for about two seconds and then load the main form. I have two forms (frmSplash and frmMain) and a code Module setup as my startup object. Here is the code that I have, when I try to run this part of the...
2
8974
by: User | last post by:
Hi, What is the best way to release all resources holded by the Timer (myTimer from class System.Timers.Timer)? Is it: 1- myTimer.dispose 2- myTimer.enabled = false 3- myTimer.close
5
9868
by: Michael C# | last post by:
Hi all, I set up a System.Timers.Time in my app. The code basically just updates the screen, but since the processing performed is so CPU-intensive, I wanted to make sure it gets updated regularly; like every 1.5 secs. or so. I only ran into one issue - the MyTimer_Elapsed event handler was not updating the screen correctly all the time,...
0
1328
by: brunft | last post by:
I was testing this with .NET Framework 2.0. Exceptions in the Elapsed event handler of a System.Timers.Timer are ignored, they are not handled by the runtime and not reported (when running outside of VS.NET) either. Ther Timer continues as if nothing happened. Is this the desired behaviour, because this would have very negative impact on...
0
1216
by: archana | last post by:
Hi all, I am facing some wired problem while using system.timers.timer in windows service. I have one function which i want to execute once day. So i set interval of my timer to 60000 *1440. Means nearly one day. In function i am generating some files. My application is working properly for say 10 to 15 days. Suddnely
7
5976
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 seems recently connections just drop off because the timer stops firing. My question is if there is a timeout in the timer event that just shuts...
5
12204
by: Tony Gravagno | last post by:
I have a class that instantiates two Timer objects that fire at different intervals. My class can be instantiated within a Windows Form or from a Windows Service. Actions performed by one of the event handlers may take longer than the interval for either of the timers, so it's possible for multiple events to fire "simultaneously" and for...
8
3362
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 on a network for files and then copies these files to another location (on the network) AND then updates a record in the database. The file copying...
0
7876
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...
0
8156
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8310
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...
1
7910
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...
0
6563
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2307
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
0
1144
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...

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.