?
Solved

SetWaitableTimer specifics

Posted on 1998-02-13
4
Medium Priority
?
881 Views
Last Modified: 2013-12-03
MSVC++ 5.0, WinNT4.0SP3

I'm trying to sync up a aircraft simulation to real-time. Becuase the model itself runs very fast (like 20simulated seconds in .2 realtime seconds), I need some kind of timer that once the model frame has been run through, it waits until the real frame time is up to continue.

I've found the WaitablTimer set of functions to be exactly what I want. However, after creating the timer and then calling SetWaitableTimer(), I am unsure of the exact specifics of what the variable inputs to this function do.

The 2nd parameter, *pDueTime in 100 nano-second intervals.... is this what I want to set the single frame time of the model as? If not, what is it for?

The 3rd paramter, lPeriod in milliseconds.....what about this? If not, what is it for?

I want to set the timer at the initialization of the model, then call WaitForSingleObject() at the bottom of each frame, so it should wait until the specified real-time frame time is up to go back through the loop again, over and over. I'm just not sure where to put the periodic cycle time I need.

btw, I don't need a completion routine (the 4th, 5th params).

Thanks,
0
Comment
Question by:gunn
[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
4 Comments
 
LVL 11

Accepted Solution

by:
alexo earned 100 total points
ID: 1411241
The 2nd parameter (pDueTime) is the first time you would like the timer to fire.
The FILETIME structure is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601.

The 3rd paramter (lPeriod) is the period of the timer.
If lPeriod is zero, the timer is signaled once.  If lPeriod is greater than zero, the timer is periodic.  A periodic timer automatically reactivates each time the period elapses, until the timer is canceled using the CancelWaitableTimer function or reset using SetWaitableTimer.

Here's a sample to set a timer to 10:00 AM with a 24 hours period:

      #define TIMER_SECOND      1000L
      #define TIMER_MINUTE      (TIMER_SECOND * 60L)
      #define TIMER_HOUR      (TIMER_MINUTE * 60L)
      #define TIMER_DAY      (TIMER_HOUR   * 24L)

      SYSTEMTIME      sysTime = GetLocalTime(&sysTime);
      FILETIME      fileTime;
      LARGE_INTEGER      dueTime;
      
      sysTime.wHour = 10;
      sysTime.wMinute = 0;
      sysTime.wSecond = sysTime.wMilliseconds = 0;

      period = 24 * TIMER_DAY;

      SystemTimeToFileTime(&sysTime, &fileTime);
      LocalFileTimeToFileTime(&fileTime, (FILETIME*)&dueTime);

      hTimer = CreateWaitableTimer(NULL, FALSE, NULL);
      SetWaitableTimer(hTimer, &dueTime, period, NULL, NULL, FALSE);


0
 
LVL 11

Expert Comment

by:alexo
ID: 1411242
Sigh...  Another autograder hit.
0
 

Author Comment

by:gunn
ID: 1411243
Sorry it took me so long to get back to these pages and this question I had posted. Haven't worked on this part of the project since then; its just been in limbo.



Thanks a lot; I'll make sure I have it set up that way.



From your example above, will the timer 'fire' after the period is up, over and over?



Thanks again!
0
 
LVL 11

Expert Comment

by:alexo
ID: 1411244
If you don't get back to an answer long enough, the EE software will automatically accept it with a 'C' grade.  Wich is usually not what you (or the "expert") want.

The answer to your question is yes, over and over.

Also, you might want to look at "multimedia timers".  They have better resolution.

0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

764 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