Running Multiple Timers

Experts,
I've created a stopwatch application based on API call 'timeGetTime' which can show 1/100 sec count.

The problem is that if I reproduce this timer (so that we have stopwatches A and B) and I launch both of them from a Form and run them simultaeously, the digital displays of timer A and B do not 'tick over' like they should. Only ONE timer at any given time shows the time counting, while the display of the other simply 'freezes'. Only when one stopwatch is stopped, does the other continue to 'tick over'.

Note that the stopwatch whose display isn't refreshing while the other is running, does continue to count the time correctly in the 'background' however, because when the display of the former resumes ticking over, it shows the correct elapsed time ie it resumes from the right place.

Any ideas as to how I can get the displays of both timers to show the time counting?

Thanks,
DocNash
DoctorNashAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vinnyd79Commented:
Have you tried adding "DoEvents" to each of the timer procedures.
0
DoctorNashAuthor Commented:
Yes the routines do contain 'Do Events'. Each timeGetTime section which loops until 1/100 s is counted, contains this command. I know this works because when a single timer is running, the application can indeed continue to do other things. Maybe in the case of multiple timers, Do Events is required in other places in the code? Would posting the code here help?
0
J-ManCommented:
There may be several reasons why this is happening.

1) Force a refresh of the label (or whatever) when it increments.
i.e.
labelTimerA.Refresh

2) Your threads may not be running simultaneously.
Try putting your code in one subroutine and update all timers in an array at once.
For Example, something like this:

Dim lTimeElapsed as Long
Dim lLastTime as Long
Dim myTimerArray() as Long
Dim iNumberofTimers as Integer
Do While (True)
 lTimeElapsed = timeGetTime - lLastTime
 lLastTime = lLastTime + lTimeElapsed
 For i = 0 to iNumberofTimers - 1
     myTimerArray(i) = myTimerArray(i) + lTimeElapsed
     labelTimer(i).Caption = myTimerArray(i)
 Next i
 DoEvents
Loop
'I'm sure this could be optimized, just thinking off the top of my head.  :-)

Posting your code might help.
0
CleanupPingCommented:
DoctorNash:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
J-ManCommented:
I may be suffering from ego-inflation, but I think my answer was best.
More help may be offered if the code is posted by DoctorNash.

However, one more suggestion is to simply place all the timer displays on one form, resize to fit and maybe add a little "X" box to close individual timers without closing the entire form.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.