?
Solved

Running Multiple Timers

Posted on 2003-03-02
5
Medium Priority
?
180 Views
Last Modified: 2010-05-01
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
0
Comment
Question by:DoctorNash
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 8053838
Have you tried adding "DoEvents" to each of the timer procedures.
0
 

Author Comment

by:DoctorNash
ID: 8053867
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
 
LVL 1

Expert Comment

by:J-Man
ID: 8054052
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
 

Expert Comment

by:CleanupPing
ID: 8900890
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
 
LVL 1

Accepted Solution

by:
J-Man earned 100 total points
ID: 8904019
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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question