Solved

SetTimer

Posted on 1998-08-24
8
310 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

813 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now