Solved

SetTimer

Posted on 1998-08-24
8
306 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

706 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

20 Experts available now in Live!

Get 1:1 Help Now