Starting a Single Timer Event

[The feature associated with this page, Multimedia Timers, is a legacy feature. It has been superseded by Multimedia Class Scheduler Service. Multimedia Class Scheduler Service has been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use Multimedia Class Scheduler Service instead of Multimedia Timers, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

Note

This topic describes an obsolete function. New applications should use the CreateTimerQueueTimer function to create timers.

 

To start a single timer event, call the timeSetEvent function, specifying the amount of time before the callback occurs, the resolution, the address of the callback function (see TimeProc), and the user data to supply with the callback function. An application can use a function like the following to start a single timer event.

UINT SetTimerCallback(NPSEQ npSeq,  // sequencer data
    UINT msInterval)                // event interval
{ 
    npSeq->wTimerID = timeSetEvent(
        msInterval,                    // delay
        wTimerRes,                     // resolution (global variable)
        OneShotCallback,               // callback function
        (DWORD)npSeq,                  // user data
        TIME_ONESHOT );                // single timer event
    if(! npSeq->wTimerID)
        return ERR_TIMER;
    else
        return ERR_NOERROR;
} 

For an example of the callback function OneShotCallback, see Writing a Timer Callback Function.

Using Multimedia Timers