Home > Software engineering >  MFC multimedia timer timer
MFC multimedia timer timer

Time:09-30

In the use of MFC timer, because the timer message response, lower precedence

Have a great god, written like MFC timer, but higher priority, finally can background processing task,

Give a demo thanks!

CodePudding user response:

Waitable Timer Objects
A "waitable timer object is A synchronization object whose state is set to signaled the when the specified due time arrives. There are two types of waitable timers that can be created: manual - reset and synchronization, A timer of either type can also be A periodic timer.

Object Description
The manual - reset timer A timer whose state remains signaled until SetWaitableTimer is called to establish A new due time.
The synchronization timer A timer whose state remains signaled until A thread of A wait operation on the timer object.
Periodic timer A timer that is reactivated each time the specified period expires, until the timer is reset or canceled. A periodic timer is either A periodic manual - reset timer or A periodic synchronization timer.


A thread uses the CreateWaitableTimer function to create a timer object. Specify TRUE for the bManualReset parameter to create a manual-reset timer and FALSE to create a synchronization timer. The creating thread can specify a name for the timer object in the lpTimerName parameter. Threads in other processes can open a handle to an existing timer by specifying its name in a call to the OpenWaitableTimer function. Any thread with a handle to a timer object can use one of the wait functions to wait for the timer state to be set to signaled.

The thread calls The SetWaitableTimer function to activate The timer. Note The use of The following parameters for SetWaitableTimer:
Use the lpDueTime parameter to specify the time at which the timer is to be set to the signaled state. When a manual - reset the timer is set to the signaled state, it remains in this state until SetWaitableTimer establishes a new due time. When a synchronization timer is set to the signaled state, it remains in this state until a thread of a wait operation on the timer object.
Use the lPeriod parameter of the SetWaitableTimer function to specify the timer period. If the period is not zero, the timer is a periodic timer; It is reactivated each time the period expires, until the timer is reset or canceled. If the period is zero, the timer is not a periodic timer; It is signaled once and then deactivated.
A thread can use the CancelWaitableTimer function to set the timer to the inactive state. To reset the timer, call SetWaitableTimer. When you are finished with the timer object, call the CloseHandle to close the handle to the timer object.

CodePudding user response:

Use multithreading timing, can set the priorities, as well as more accurate timing,

CodePudding user response:

Can wait for the timer object
"Waiting for" the timer object is a synchronization object's state is set to have signal, arrive at the appointed time, because there are two kinds of can wait for the timer, you can create: manual reset and synchronization, any type of timer can also be a cycle timer,
Object description
Manual reset timer, timer status still says, until setwaitabletimer known as the creation of a new maturity,
Synchronous timer: before the thread is waiting for operation of the timer object finished its state to keep the signal timer,
Cycle timer: after each specified time due to restart the timer, until the timer is reset or cancel, cycle timer is periodic manual reset timer or periodic synchronization timer,
A thread using createwaitabletimer function to create a timer object, specify really bmanualreset parameter to create a manual reset timers and false to create a synchronous timer, timer object can create a thread in the lptimername parameter to specify a name, in the process of the other threads can open a handle to an existing openwaitabletimer timer specifies the names of the function call, any thread with a handle to the timer object can use one of the wait functions to wait for the timer state is set to signal,
The calling thread setwaitabletimer activate the timer function, pay attention to the following parameters using setwaitabletimer:
Use lpduetime parameter specifies the time of the timer is set to end state, when the manual reset timer is set to signal state, remain in this state until setwaitabletimer established a new maturity, when the synchronous timer is set to signaled it will remain in this state, until the thread on the timer object waiting for operation,
Using phase setwaitabletimer function parameter specifies the timer cycle, if the cycle is not zero, the timer is a cycle timer, it is reactivated each time expires, until the timer is reset or cancelled, if the cycle is zero, the timer is not periodic timer, it emits a signal, and then stopped,
A thread can use cancelwaitabletimer function to set the timer to inactive, reset the timer, called setwaitabletimer, when you have completed the timer object, call the CloseHandle closed processing timer object,

CodePudding user response:

http://m.blog.csdn.net/article/details? Id=8134064

CodePudding user response:

Remind: 15 ms Windows timing precision material
  • Related