473,692 Members | 2,342 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

'************** *************** *************** *************** *************** ****
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()

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

'Add any initialization after the InitializeCompo nent()

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
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
'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()
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")
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")
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"
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
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
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
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

Me.Cursor = Cursors.WaitCur sor

End Sub

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

If Date.Now > TargetTime Then
Me.DialogResult = DialogResult.OK
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 11115
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).

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?


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?


"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?


Apr 12 '06 #4

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.


Apr 12 '06 #5

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

Similar topics

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;
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 splash screen form shows and then program terminates. What am I doing wrong? Thanks,
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
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, often leaving large chunks of the screen un-painted for several seconds. On a whim I decided to...
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 analysis of unexpected errors? Am i missing any design directives concerining the exception handling...
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
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 down the call if the timer event is taking too long to complete...?
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 events to queue up. I'm attempting to get the timers to sync on some reference type object, or use...
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 is performed before the database update because the file system is not transactional. The code...
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...
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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,...
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.