473,327 Members | 2,074 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,327 software developers and data experts.

Any reason for an enabled timer not to fire or count down?

I have a timer on a form. It isn't firing at all. I know that the timer is
enabled, and that the interval is low (4000, which should be 4 seconds). To
ensure the timer wasn't being inadvertantly reset I put some extra code in
the subs that enable and disable the timer. They fire as expected.

To test this I added a second timer with a 1 second interval. The event for
this time would output the enabled status of the first timer and its
interval value. I saw "TRUE 4000" appear each second.

Should the 4000 value decrease over time, or is this static with an internal
counter being used by the timer?

Since the timer is showing as enabled, why doesn't it fire after four
seconds?

Also, what is the bestest way to reset the interval? This is the sub I call
to reset my timeout timer.
'Reset the timeout timer
Private Sub ResetTimeout()
timTimeout.Enabled = False
timTimeout.Interval = uTimeout * 1000
timTimeout.Enabled = True
End Sub
Nov 20 '05 #1
7 2354
Hi there... The way the timer works is you set the interval to a value in
milliseconds, then after the time has elapsed, the "Tick" event is fired.

Then it waits another "Interval" milliseconds and fires "Tick"... and so on,
until it's set to disabled (or the application exits).

By default, I believe the Timer has .Enabled = False, so you set the
interval then enable the timer...

Timer1.Interval = 4000
Timer1.Enabled = True

Every 4 seconds the Tick event of the timer will fire.

If you only want it to fire once, then in the Tick event, simply set
Timer1.Enabled = False...

Public Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Timer1.Tick
DirectCast(sender, Timer).Enabled = False
End Sub

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

" System.Reflection Master "

==== Converting to 2002 ====
Remove inline declarations
"Noozer" <po********@127.0.0.1> wrote in message
news:eR**************@TK2MSFTNGP11.phx.gbl...
I have a timer on a form. It isn't firing at all. I know that the timer is
enabled, and that the interval is low (4000, which should be 4 seconds). To ensure the timer wasn't being inadvertantly reset I put some extra code in
the subs that enable and disable the timer. They fire as expected.

To test this I added a second timer with a 1 second interval. The event for this time would output the enabled status of the first timer and its
interval value. I saw "TRUE 4000" appear each second.

Should the 4000 value decrease over time, or is this static with an internal counter being used by the timer?

Since the timer is showing as enabled, why doesn't it fire after four
seconds?

Also, what is the bestest way to reset the interval? This is the sub I call to reset my timeout timer.
'Reset the timeout timer
Private Sub ResetTimeout()
timTimeout.Enabled = False
timTimeout.Interval = uTimeout * 1000
timTimeout.Enabled = True
End Sub

Nov 20 '05 #2
"Noozer" <po********@127.0.0.1> schrieb
I have a timer on a form. It isn't firing at all. I know that the
timer is enabled, and that the interval is low (4000, which should be
4 seconds). To ensure the timer wasn't being inadvertantly reset I
put some extra code in the subs that enable and disable the timer.
They fire as expected.

To test this I added a second timer with a 1 second interval. The
event for this time would output the enabled status of the first
timer and its interval value. I saw "TRUE 4000" appear each
second.

Should the 4000 value decrease over time, or is this static with an
internal counter being used by the timer?

Since the timer is showing as enabled, why doesn't it fire after
four seconds?

Also, what is the bestest way to reset the interval? This is the sub
I call to reset my timeout timer.
'Reset the timeout timer
Private Sub ResetTimeout()
timTimeout.Enabled = False
timTimeout.Interval = uTimeout * 1000
timTimeout.Enabled = True
End Sub


How do declare the first (4 sec.) timer and how do you add the event
handler?
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3

"Armin Zingler" <az*******@freenet.de> wrote in message
news:Ou**************@TK2MSFTNGP12.phx.gbl...
"Noozer" <po********@127.0.0.1> schrieb
I have a timer on a form. It isn't firing at all. I know that the
timer is enabled, and that the interval is low (4000, which should be
4 seconds). To ensure the timer wasn't being inadvertantly reset I
put some extra code in the subs that enable and disable the timer.
They fire as expected.
How do declare the first (4 sec.) timer and how do you add the event
handler?


I've tried to include all the relevent code without the extra bits... Let me
know if it isn't sufficient. (Also let me know if you want me to post again
with wrapping disabled)

uTimeout has a value of 4 at the start of the program. The timeout timer
(timTimeout) is not enabled until the CONNECT sub is called and is
succesful.

'Open a connection to a server to the specified address and port.
Public Function Connect(ByVal Server As String, ByVal port As Int16) As
Boolean
If uConnected Then 'If we are already connected we should disconnect first
Disconnect()
End If
Try 'Error trap in case connection fails
client = New TcpClient(Server, port) 'Create connection
'Attach our "DoRead" sub to handle incoming data.
client.GetStream.BeginRead(ReadBuffer, 0, ReadBufferSize, AddressOf
DoRead, Nothing)
Clear() 'Clear the display
MarkConnected() 'Set state of this control to connected (enable timeout
timer, set flags, etc.)
Return True 'No errors, so we were successful. Return TRUE.
Catch ex As Exception
'Error occurred while trying to connect
DisplaySystem("Error - '" & ex.Message & "'") 'Write error to console
MarkDisconnected() 'Mark this control as disconnected (disable timeout
timer, set flags, etc.)
Return False 'No connection so return FALSE
End Try
End Function

'This routine handles incoming data from our TCP "client" object
Private Sub DoRead(ByVal ar As IAsyncResult)
Dim BytesRead As Integer 'Number of bytes in buffer
Dim Data As String 'String read from buffer
Try 'Error trapping
BytesRead = client.GetStream.EndRead(ar) 'Get # of bytes available
If BytesRead < 1 Then 'If there is no data to read, we should assume
we're disconnected.
MarkDisconnected()
Exit Sub
End If
ResetTimeout() 'Reset the timeout timer since there is incoming data
'Convert incoming data to a string...
Data = Encoding.ASCII.GetString(ReadBuffer, 0, BytesRead)
DisplayIn(Data) 'Display incoming data to display
'Start a new asyncronous read into buffer
client.GetStream.BeginRead(ReadBuffer, 0, ReadBufferSize, AddressOf
DoRead, Nothing)
Catch ex As Exception
'Error occured
DisplaySystem("Error - '" & ex.Message & "'") ' Display error
MarkDisconnected() 'Set as disconnected since there was an error.
End Try
End Sub

'Send data to remote connection, appending a CR/LF to data. Return TRUE if
successful
Public Function SendLn(ByVal data As String) As Boolean
Return Send(data & Chr(10) & Chr(13))
End Function

'Send data to remote connection. Return TRUE if successful
Public Function Send(ByVal data As String) As Boolean
Try
Dim writer As New IO.StreamWriter(client.GetStream) 'Declare stream
writer
writer.Write(data) 'Send data to stream
writer.Flush() 'Flush stream to remote connection
DisplayOut(data) 'Send outgoing data to display
ResetTimeout() 'Reset timeout timer
Return True 'Success! Return TRUE
Catch ex As Exception
'Error occurred. Not successful.
DisplaySystem("Error - '" & ex.Message & "'")
MarkDisconnected() 'Assume disconnected because of error.
Return False 'Unsuccessful send. Return FALSE.
End Try
End Function

'Send incoming text to the display.
Private Sub DisplayIn(ByVal text As String)
rtbDisplay.SelectionColor = uInColor
rtbDisplay.SelectionFont = uInStyle
rtbDisplay.AppendText(text)
End Sub

'Send outgoing text to the display.
Private Sub DisplayOut(ByVal text As String)
rtbDisplay.SelectionColor = uOutColor
rtbDisplay.SelectionFont = uOutStyle
rtbDisplay.AppendText(text)
End Sub

'Send system text to the display.
Private Sub DisplaySystem(ByVal text As String)
rtbDisplay.SelectionColor = uSysColor
rtbDisplay.SelectionFont = uSysStyle
rtbDisplay.AppendText(text)
End Sub

'Send user text to the display. This is externally generated test.
Public Sub DisplayUser(ByVal text As String)
rtbDisplay.SelectionColor = uUserColor
rtbDisplay.SelectionFont = uUserStyle
rtbDisplay.AppendText(text)
End Sub

'Send user text to the display, followed by a carriage return.
Public Sub DisplayUserLine(ByVal text As String)
DisplayUser(text & Chr(13))
End Sub

'Close current connection. Return TRUE if close was normal.
Public Function Disconnect()
If uConnected = False Then
Return True 'We're already disconnected. Nothing to do.
End If
Try 'Error trap
client.Close() 'Try and close connection
client = Nothing 'Destroy our connection object
MarkDisconnected() 'Set state of this control to disconnected
Return True 'Close was normal. Return TRUE.
Catch ex As Exception
DisplaySystem("Error - '" & ex.Message & "'")
MarkDisconnected() 'There was an error during disconnect. Assume
disconnect.
Return False 'Normal close did not occur. Return FALSE.
End Try
End Function

'Set this control to disconnected state
Private Sub MarkDisconnected()
If uConnected Then 'Only do this if we aren't already in a disconnected
state
uConnected = False
timTimeout.Enabled = False 'Turn off timeout timer
DisplaySystem("Disconnected" & Chr(13))
RaiseEvent StateChanged(False, Me)
End If
End Sub

'Set this control to a connected state
Private Sub MarkConnected()
If Not uConnected Then 'Only do this if we aren't already connected
uConnected = True
timTimeout.Interval = uTimeout * 1000 'Set timeout interval for
timeout timer
timTimeout.Enabled = True 'Enable the timeout
timer
DisplaySystem("Connected..." & Chr(13)) 'Send CONNECTED to display
RaiseEvent StateChanged(True, Me) 'Raise event to indicate state
change.
End If
End Sub

'Clear display area
Public Sub Clear()
rtbDisplay.Clear()
End Sub

'Timeout has fired. We are disconnecting.
Private Sub timTimeout_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles timTimeout.Tick
Disconnect()
DisplaySystem("Application timeout. Disconnected.")
End Sub

'Reset the timeout timer
Private Sub ResetTimeout()
timTimeout.Enabled = False
timTimeout.Interval = uTimeout * 1000
timTimeout.Enabled = True
End Sub
Nov 20 '05 #4
> "Armin Zingler" <az*******@freenet.de> wrote in message
news:Ou**************@TK2MSFTNGP12.phx.gbl...
"Noozer" <po********@127.0.0.1> schrieb
I have a timer on a form. It isn't firing at all. I know that the
timer is enabled, and that the interval is low (4000, which should be
4 seconds). To ensure the timer wasn't being inadvertantly reset I
put some extra code in the subs that enable and disable the timer.
They fire as expected.
How do declare the first (4 sec.) timer and how do you add the event
handler?


I've tried to include all the relevent code without the extra bits... Let

me know if it isn't sufficient.
Ever more than.. ;-)
(Also let me know if you want me to post again
with wrapping disabled)
No, thanks, after adding some declarations it is compilable.

Is it possible that you call sub ResetTimeout quite frequently?
'Reset the timeout timer
Private Sub ResetTimeout()
timTimeout.Enabled = False
timTimeout.Interval = uTimeout * 1000
timTimeout.Enabled = True

Debug.Writeline now & " ResetTimeout"
End Sub

--
Armin

Nov 20 '05 #5
.... I don't expect anyone to pick through this code and exclaim "Eureka!" I
was just hoping that someone may have some idea of a scenario that would
cause a timer not to fire.

The only thing I assume would stop a timer from firing is if it fired once
and never finished executing its code, but that isn't the case here.

A bit more info... I'm connecting to a POP3 server to test the control. I
connect to the server successfully and the welcome banner displays. There is
no more data from the remote connection and the application just sits, and
should time out after four seconds, but never does.
"Noozer" <po********@127.0.0.1> wrote in message
news:KnpGb.810051$6C4.754551@pd7tw1no...

"Armin Zingler" <az*******@freenet.de> wrote in message
news:Ou**************@TK2MSFTNGP12.phx.gbl...
"Noozer" <po********@127.0.0.1> schrieb
I have a timer on a form. It isn't firing at all. I know that the
timer is enabled, and that the interval is low (4000, which should be
4 seconds). To ensure the timer wasn't being inadvertantly reset I
put some extra code in the subs that enable and disable the timer.
They fire as expected.
How do declare the first (4 sec.) timer and how do you add the event
handler?


I've tried to include all the relevent code without the extra bits... Let

me know if it isn't sufficient. (Also let me know if you want me to post again with wrapping disabled)

uTimeout has a value of 4 at the start of the program. The timeout timer
(timTimeout) is not enabled until the CONNECT sub is called and is
succesful.

'Open a connection to a server to the specified address and port.
Public Function Connect(ByVal Server As String, ByVal port As Int16) As
Boolean
If uConnected Then 'If we are already connected we should disconnect first Disconnect()
End If
Try 'Error trap in case connection fails
client = New TcpClient(Server, port) 'Create connection
'Attach our "DoRead" sub to handle incoming data.
client.GetStream.BeginRead(ReadBuffer, 0, ReadBufferSize, AddressOf
DoRead, Nothing)
Clear() 'Clear the display
MarkConnected() 'Set state of this control to connected (enable timeout
timer, set flags, etc.)
Return True 'No errors, so we were successful. Return TRUE.
Catch ex As Exception
'Error occurred while trying to connect
DisplaySystem("Error - '" & ex.Message & "'") 'Write error to console
MarkDisconnected() 'Mark this control as disconnected (disable timeout
timer, set flags, etc.)
Return False 'No connection so return FALSE
End Try
End Function

'This routine handles incoming data from our TCP "client" object
Private Sub DoRead(ByVal ar As IAsyncResult)
Dim BytesRead As Integer 'Number of bytes in buffer
Dim Data As String 'String read from buffer
Try 'Error trapping
BytesRead = client.GetStream.EndRead(ar) 'Get # of bytes available
If BytesRead < 1 Then 'If there is no data to read, we should assume
we're disconnected.
MarkDisconnected()
Exit Sub
End If
ResetTimeout() 'Reset the timeout timer since there is incoming data
'Convert incoming data to a string...
Data = Encoding.ASCII.GetString(ReadBuffer, 0, BytesRead)
DisplayIn(Data) 'Display incoming data to display
'Start a new asyncronous read into buffer
client.GetStream.BeginRead(ReadBuffer, 0, ReadBufferSize, AddressOf
DoRead, Nothing)
Catch ex As Exception
'Error occured
DisplaySystem("Error - '" & ex.Message & "'") ' Display error
MarkDisconnected() 'Set as disconnected since there was an error.
End Try
End Sub

'Send data to remote connection, appending a CR/LF to data. Return TRUE if
successful
Public Function SendLn(ByVal data As String) As Boolean
Return Send(data & Chr(10) & Chr(13))
End Function

'Send data to remote connection. Return TRUE if successful
Public Function Send(ByVal data As String) As Boolean
Try
Dim writer As New IO.StreamWriter(client.GetStream) 'Declare stream
writer
writer.Write(data) 'Send data to stream
writer.Flush() 'Flush stream to remote connection
DisplayOut(data) 'Send outgoing data to display
ResetTimeout() 'Reset timeout timer
Return True 'Success! Return TRUE
Catch ex As Exception
'Error occurred. Not successful.
DisplaySystem("Error - '" & ex.Message & "'")
MarkDisconnected() 'Assume disconnected because of error.
Return False 'Unsuccessful send. Return FALSE.
End Try
End Function

'Send incoming text to the display.
Private Sub DisplayIn(ByVal text As String)
rtbDisplay.SelectionColor = uInColor
rtbDisplay.SelectionFont = uInStyle
rtbDisplay.AppendText(text)
End Sub

'Send outgoing text to the display.
Private Sub DisplayOut(ByVal text As String)
rtbDisplay.SelectionColor = uOutColor
rtbDisplay.SelectionFont = uOutStyle
rtbDisplay.AppendText(text)
End Sub

'Send system text to the display.
Private Sub DisplaySystem(ByVal text As String)
rtbDisplay.SelectionColor = uSysColor
rtbDisplay.SelectionFont = uSysStyle
rtbDisplay.AppendText(text)
End Sub

'Send user text to the display. This is externally generated test.
Public Sub DisplayUser(ByVal text As String)
rtbDisplay.SelectionColor = uUserColor
rtbDisplay.SelectionFont = uUserStyle
rtbDisplay.AppendText(text)
End Sub

'Send user text to the display, followed by a carriage return.
Public Sub DisplayUserLine(ByVal text As String)
DisplayUser(text & Chr(13))
End Sub

'Close current connection. Return TRUE if close was normal.
Public Function Disconnect()
If uConnected = False Then
Return True 'We're already disconnected. Nothing to do.
End If
Try 'Error trap
client.Close() 'Try and close connection
client = Nothing 'Destroy our connection object
MarkDisconnected() 'Set state of this control to disconnected
Return True 'Close was normal. Return TRUE.
Catch ex As Exception
DisplaySystem("Error - '" & ex.Message & "'")
MarkDisconnected() 'There was an error during disconnect. Assume
disconnect.
Return False 'Normal close did not occur. Return FALSE.
End Try
End Function

'Set this control to disconnected state
Private Sub MarkDisconnected()
If uConnected Then 'Only do this if we aren't already in a disconnected
state
uConnected = False
timTimeout.Enabled = False 'Turn off timeout timer
DisplaySystem("Disconnected" & Chr(13))
RaiseEvent StateChanged(False, Me)
End If
End Sub

'Set this control to a connected state
Private Sub MarkConnected()
If Not uConnected Then 'Only do this if we aren't already connected
uConnected = True
timTimeout.Interval = uTimeout * 1000 'Set timeout interval for
timeout timer
timTimeout.Enabled = True 'Enable the timeout
timer
DisplaySystem("Connected..." & Chr(13)) 'Send CONNECTED to display
RaiseEvent StateChanged(True, Me) 'Raise event to indicate state change.
End If
End Sub

'Clear display area
Public Sub Clear()
rtbDisplay.Clear()
End Sub

'Timeout has fired. We are disconnecting.
Private Sub timTimeout_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles timTimeout.Tick
Disconnect()
DisplaySystem("Application timeout. Disconnected.")
End Sub

'Reset the timeout timer
Private Sub ResetTimeout()
timTimeout.Enabled = False
timTimeout.Interval = uTimeout * 1000
timTimeout.Enabled = True
End Sub

Nov 20 '05 #6

"Armin Zingler" <az*******@freenet.de> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
"Armin Zingler" <az*******@freenet.de> wrote in message
news:Ou**************@TK2MSFTNGP12.phx.gbl...
"Noozer" <po********@127.0.0.1> schrieb
> I have a timer on a form. It isn't firing at all. I know that the
> timer is enabled, and that the interval is low (4000, which should be > 4 seconds). To ensure the timer wasn't being inadvertantly reset I
> put some extra code in the subs that enable and disable the timer.
> They fire as expected.
How do declare the first (4 sec.) timer and how do you add the event
handler?


I've tried to include all the relevent code without the extra bits... Let me
know if it isn't sufficient.


Ever more than.. ;-)
(Also let me know if you want me to post again
with wrapping disabled)


No, thanks, after adding some declarations it is compilable.

Is it possible that you call sub ResetTimeout quite frequently?


Yes... After each block of data from the connection as well as after sending
any data. Are there issues with how I'm trying to reset the timer? The code
below doesn't seem 'correct' to get the timer to restart to me.
'Reset the timeout timer
Private Sub ResetTimeout()
timTimeout.Enabled = False
timTimeout.Interval = uTimeout * 1000
timTimeout.Enabled = True

Debug.Writeline now & " ResetTimeout"
End Sub

Nov 20 '05 #7
"Noozer" <po********@127.0.0.1> schrieb
Is it possible that you call sub ResetTimeout quite frequently?


Yes... After each block of data from the connection as well as after
sending any data. Are there issues with how I'm trying to reset the
timer? The code below doesn't seem 'correct' to get the timer to
restart to me.
'Reset the timeout timer
Private Sub ResetTimeout()
timTimeout.Enabled = False
timTimeout.Interval = uTimeout * 1000
timTimeout.Enabled = True

Debug.Writeline now & " ResetTimeout"
End Sub

Well, if you restart the timer each 3 seconds, it will never fire if
interval = 4000. If this is not the case, I don't have a clue at current.
--
Armin

Nov 20 '05 #8

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

Similar topics

1
by: Will | last post by:
I have form showing instructions and logging actions and I would like the form to show a count down timer for a certain period of time. E.g. 30 secs, going down to 0 and then displaying the action....
2
by: Michael Evans | last post by:
First, we rely on a stable update rate so that our physics and dynamics calculations and integrations are based on a known interval and therefore are true-to-life. Second, the graphics positions...
1
by: logdenav | last post by:
Hello I'm testing the performance of the System.Timers.Timer class. I created a small program that create 100 User objects. Each USer object create a MyTimer object. The constructor of the User...
6
by: Steve | last post by:
I am working on a emulator and need to have time based events. I've tried to use the timer control and discovered that it runs waaaaaaay slow. I set the tick frequency to 1, then in the tick...
2
by: HeroinNO.4 | last post by:
Copy the code below and save in a .htm file, for example : 1.htm, then run it in browser, you'll see a cool count down timer ! If it doesn't work, you may open http://www.fillweb.com in IE and...
2
by: HeroinNO.4 | last post by:
Hello everyone! Now the latest version of free count down timer source code is available in http://www.fillweb.com/countdown.htm, you can open it in IE and View->Source to see the latest version...
7
by: HeroinNO.4 | last post by:
Hello guys, free count down timer source code has updated to 06/11/27, you can copy the code below and save in a ".htm" file and run it in a browser support javascript 1.1 or later, or you can open...
3
missshaikh
by: missshaikh | last post by:
Hi all, i need the count down timer when button click the timer start and count down work on ASP.net :( i have one timer which is on JavaScript that run page onload . but i need the Button...
2
by: =?Utf-8?B?U3VyZXNoIFJlZGR5?= | last post by:
I am getting a strange problem with IE7 tabs. The web application I am working (developed in ASP.Net, .Net 2.0), will show a popup message with the count down timer 2 minutes before session time...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.