Solved

SetTimer

Posted on 1998-08-24
8
311 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is the real difference between C++ and Visual C++.NET? 7 120
How to gracefully close the c++ 11 thread? 3 108
No module found pypyodbc, 3 32
C++ Code Issue 4 25
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

856 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