473,382 Members | 1,400 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,382 software developers and data experts.

Why doesn't timer tick

I have a timer enabled on a form with an interval of 200. I place a break
point on the first line in the timer tick event, which is a try. After a
few events go on, the timer seems to stop. My break point is no longer hit.
In the debugger, the timer shows enabled and the interval is still set.

Any ideas what may be happening or something else I can check?

Thanks,
Brett
Nov 21 '05 #1
9 7173
Brett,

There are at least 3 timers in Net. Therefore tell us which.

Do you as well disable the timer when it is fired in the event. Otherwise it
keeps on firing and than you will become crazy when setting a breakpoin and
debug. The events are throwed, however you see everytime another one.

I hope this help

Cor
Nov 21 '05 #2
I'm using System.Windows.Forms.Timer. Yes - I disable it in the timer event
but reenable it. If I set a break point outside of the timer event and
check the timer1.enabled property, which is true, shouldn't the timer be
firing?

Yes - the debugger does jump all over the place when the event is firing.
After a few actions in the software, the event stops firing but
timer1.enabled = true. I could post a bunch of code but was wondering why
timer1.enabled = true and the event in fact isn't firing. How can
timer1.enabled = true and the event not fire?

Thanks,
Brett
"Cor Ligthert" <no************@planet.nl> wrote in message
news:et**************@TK2MSFTNGP14.phx.gbl...
Brett,

There are at least 3 timers in Net. Therefore tell us which.

Do you as well disable the timer when it is fired in the event. Otherwise
it keeps on firing and than you will become crazy when setting a breakpoin
and debug. The events are throwed, however you see everytime another one.

I hope this help

Cor

Nov 21 '05 #3
Brett,

Can you show the code in that event?
(First copied in a notebook, than pasted back in a message otherwise it is
almost unreadable)
Cor
Nov 21 '05 #4

"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Brett,

Can you show the code in that event?
(First copied in a notebook, than pasted back in a message otherwise it is
almost unreadable)
Cor


Here is the timer tick event code. This is the only place timer is being
disabled/enabled. The interval is set at 200. Thanks.

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick

Dim CurThreadStart As ThreadStart
Dim CurThread As Thread
Dim ThreadCount As Integer
Dim MaxThreads As Integer = 5
Dim i As Integer

Try

If Not tcpListener.Pending() Then
Exit Sub
End If

Timer1.Enabled = False

If ActiveThreads > CInt(MaxThreads) Then
Timer1.Enabled = True
Exit Sub
End If

CurThreadStart = New ThreadStart(AddressOf Listen)

CurThread = New Thread(CurThreadStart)

CurThread.IsBackground = True
CurThread.Start()
SyncLock CurThread
ActiveThreads += 1
'write to log file
utility.WriteToFile(CurrentDirectory.GetCurrentDir ectory,
LogFileExec, utility.CurrentDateTime(0) & " - ActiveThreads = " &
ActiveThreads)
End SyncLock

Timer1.Enabled = True

Catch ex As Exception
If InStr(ex.Message, "Not listening") Then
'write to log file
utility.WriteToFile(CurrentDirectory.GetCurrentDir ectory,
LogFileError, utility.CurrentDateTime(0) & " - ERROR [Timer1_Tick] " &
ex.Message & vbCrLf)
Else

End If

End Try

End Sub
Nov 21 '05 #5
Brett,

Before I start looking at that timer, I have the idea that what you want to
do is something I have looked in past a long time for and is easy to find
now in this newsgroup.

There are than two solutions.
Use a loop with in it as long there are threads active
\\\
do your testing
threading.thread.sleep(200)
applications.doevents
///
And what I use now, is let the thread throw an event when it is ready (and
give the information back using a parameter in that event) what I catch in
the mainthread.

However when you are doing something else, reply than.

Cor
Nov 21 '05 #6

"Cor Ligthert" <no************@planet.nl> wrote in message
news:OO**************@TK2MSFTNGP09.phx.gbl...
Brett,

Before I start looking at that timer, I have the idea that what you want
to do is something I have looked in past a long time for and is easy to
find now in this newsgroup.

There are than two solutions.
Use a loop with in it as long there are threads active
\\\
do your testing
threading.thread.sleep(200)
applications.doevents
///
And what I use now, is let the thread throw an event when it is ready (and
give the information back using a parameter in that event) what I catch
in the mainthread.

However when you are doing something else, reply than.

Cor


Could you give a small code example of what you mean on the above?

Thanks,
Brett
Nov 21 '05 #7

"Cor Ligthert" <no************@planet.nl> wrote in message
news:OO**************@TK2MSFTNGP09.phx.gbl...
Brett,

Before I start looking at that timer, I have the idea that what you want
to do is something I have looked in past a long time for and is easy to
find now in this newsgroup.

There are than two solutions.
Use a loop with in it as long there are threads active
\\\
do your testing
threading.thread.sleep(200)
applications.doevents
///
And what I use now, is let the thread throw an event when it is ready (and
give the information back using a parameter in that event) what I catch
in the mainthread.

However when you are doing something else, reply than.

Cor


Maybe one problem is everything being on the same thread. I'm doing this:

sub first
While true
--do something
thread.sleep(500)
If something else then
timer.enabled = false
exit while
end if
end while

timer.enable = true
end sub

sub timer_tick
-- check tcplistener.pending()
end sub

It's almost as if the timer doesn't really get a slice of time on the
current thread. I believe the timer_tick event should be place in another
class since it checks for pending() tcp/ip connections. If there is a
pending(), it will spawn a new thread for the while loop. Comments?

Thanks,
Brett
Nov 21 '05 #8
Brett,

I mean don't use the forms timer for this, when the thread is sleeping it is
not giving a response.

You can use the threading.thread.timers which runs on seperated threads..

However that event to sent back or that loop with a thread sleep gave for me
the same effect.

However I have not that "good" expirience with those threading thread
timers. (I could not abort them even when the program was stopped).

Cor
Nov 21 '05 #9
The problem with threading.thread.timers is it runs from the ThreadPool and
will fire independant of the GUI. You then must use Invoke to update the
GUI controls to be sure the threads are in sync.

However, I will put the GUI on one thread and everything else into its own
class with another thread.

Brett

"Cor Ligthert" <no************@planet.nl> wrote in message
news:ur**************@TK2MSFTNGP12.phx.gbl...
Brett,

I mean don't use the forms timer for this, when the thread is sleeping it
is not giving a response.

You can use the threading.thread.timers which runs on seperated threads..

However that event to sent back or that loop with a thread sleep gave for
me the same effect.

However I have not that "good" expirience with those threading thread
timers. (I could not abort them even when the program was stopped).

Cor

Nov 21 '05 #10

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

Similar topics

7
by: J. Hill | last post by:
I have a Windows Service with a timer but the .Tick event is not being fired/called. Don't know what code to include...I enabled and started the timer...I have the exact same code in a Windows...
4
by: redneon | last post by:
I've set up a seperate thread and put a timer in it but for some reason it's tick event is never fired. This is what I have... .... Thread timerThread = new Thread(new ThreadStart(startTimer));...
1
by: VMI | last post by:
I have several procedures that are executed when the Timer.Tick event is run. How can I make sure that those procedures are not executed again (by the Tick event) if the previously-called...
14
by: Crirus | last post by:
This is more a logical problem than a VB. I have this situation: A timer that need to tick at each 10 minutes starting on minute 15 of curent hour. But I want to calculate the next tick...
10
by: Bob | last post by:
I have a splashscreen running on a thread from Sub Main and it works OK. It displays information in a statusbar about queries. I also have a time on the splashscreen, but the tick event never...
2
by: Bernie Yaeger | last post by:
I'm trying to create a custom control that contains both a combobox and a timer. Any ideas how I can accomplish this? I do know how to create a 'one control' inheritance control, but when I add...
17
by: Ratnesh Raval | last post by:
hi all, i m having some problem in timer control. sub timer.tick() timer.stop() do...something timer.enabled = true end sub
8
by: KnighT | last post by:
I have a .net service that runs a System.Threading.Timer. The delegate points to the function that the service should execute when the timer elapses. Problem: The timer is not ticking. I have...
16
by: Peter Oliphant | last post by:
Note that although this involves SAPI, it is more a question about Timers and event handlers. I wrote a Speech Recognize handler (SAPI), and put some code in it to enable a Timer. It would not...
12
by: Zytan | last post by:
I have a Timer class set to trigger every second. The Tick function that is called every second uses a lock to prevent multiple ticks from executing the same code at the same time. The code...
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...
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: 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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.