Solved

SetTimer

Posted on 1998-08-24
8
307 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
cb: unreferenced local variable 11 72
SetCurrentDirectory path limit 7 105
Header Errors LNK2019, LNK1120 - Unresolved Externals 4 93
C++ mouse_event mouse look 7 70
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 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.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

911 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

19 Experts available now in Live!

Get 1:1 Help Now