Solved

SetTimer

Posted on 1998-08-24
8
313 Views
Last Modified: 2010-04-10
Hi everyone...
I have a program that needs two timers running simultaneously... is that possible with Visual C++ version 5?
Thanks
0
Comment
Question by:rose337
[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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 11

Accepted Solution

by:
alexo earned 50 total points
ID: 1171049
Sure!  You can see that SetTimer() accepts an 'nIDEvent' argument which is an integer that acts as the timer ID.

Note however that timers are not a C++ feature.  Such questions are better asked in the MFC or the windows programming areas.
0
 
LVL 2

Expert Comment

by:warmcat
ID: 1171050
Bah, alexo 'lightning fingers' beat me to it.

Yes indeedie.  Just use SetTimer() twice with different nIdEvent numbers.  On a WM_TIMER message arriving, examine wParam against the nIdEvent numbers used in SetTimer() to find out which of your timers fired.  In MFC, OnTimer() has a UINT nIDEvent parameter that does the same job.

Regards,

-Andy
0
 
LVL 11

Expert Comment

by:alexo
ID: 1171051
On the other hand, you can use two TIMERPROC functions and forget about WM_TIMER messages.  Not my preferred solution but it has its merits.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Expert Comment

by:tsauy
ID: 1171052
Win'95/98 has a system timer of low acuracy. It seems to me that only the timer slower than
20 Hz is acceptable on a 200MHz Pentium PC. On the other hand, NT has much better results.
0
 

Expert Comment

by:stiff
ID: 1171053
Regarding tsauy's comment concerning the accuracy of the Win95 timer routines. There are two more significant problems which cannot be avoided even if the timing routine is hand crafted. First, there is no way in the win95 environment (that I'm aware of) to disable the non-maskable interrupts. This means that any system level function which is driven by these interrupts (such as disk access) will affect the accuracy of the timer. Second, there is an inherent execution latency in the win95 operating system of up to 150 milliseconds. This means that even though your code is clean, if there is another process running which the scheduler deems of high enough priority, it will execute and any event which terminates during that interval will not register as finished until control is returned to your program. The only solution which we have found which enabled us to circumvent this problem was to use a non-multitasking environment such as MS-DOS (yes it is still of value). The latency problem will affect any preemtive multitasking OS.
0
 
LVL 2

Expert Comment

by:warmcat
ID: 1171054
stiffy -

In fact there is no upper limit to the '95 interrupt latency, and it's nothing to do with the scheduler.  This behaviour is caused by Ring 0 VxDs turning off Ring 0 interrupts while they get on with some long process.  It is these interrupts which are the backbone of the preemprive multitasking, and if they're locked out the VxD has, uh, uninterrupted access to the CPU.  The most common culprits here are video drivers, the Matrox Mystique one having been observered by myself to provoke latencies > 300mS.  Intensive disk access was observed to provoke latencies longer than 1 second!  This was on a 300MHz P2 using a 'scope to measure the time between the IRQ and the action of the service routine.

Also, I rather suspect that the question was posed by someone wanting a long, maybe multisecond, period regular event where the jitter is not important.

Regards,

-Andy
0
 
LVL 2

Expert Comment

by:warmcat
ID: 1171055
... oh, and:

>The latency problem will affect any preemtive multitasking OS.
 
Is not true, 'hard real time' OSs such as VxWorks offer guaranteed interrupt latencies which can be quite reasonable.  It's the implementation of '95's guts which allow outrages like 1 second latencies.
0
 

Expert Comment

by:stiff
ID: 1171056
warmcat

I appreciate your comments. I was simply thinking in terms of
Visual C++ (as stated in the question).

Regards Stiff (stiffy? ...oh brother!)
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

734 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