I’m writing an event handling function, f(d), which receives some data, d, and must take take an action X(d), then sleep for 100ms, then take another action Y(d). I would implement it as:
void f(d)
{
X(d);
Sleep(100);
Y(d);
}
However, f(d) is called from a single-threaded event handler, so the Sleep(100) is unacceptable.
I would like to do the following:
void f(d)
{
X(d);
ScheduleOneShotTimer(Y,d,100);
}
I could implement ScheduleOneShotTimer by creating a new thread for each call, passing the data as the thread parameter, and calling Sleep before executing Y(d). However, as this event may occur up to 100 times per second, I’m concerned about the overhead involved with creating a destroying all those threads.
Preferably there would be operating system level support for a “one-shot timer”, but I don’t think this is the case on CE. I know about SetTimer, but that is not applicable to me because I am writing a “Console Application” that has no message loop.
Any other suggestions for how to structure this would be appreciated.
Call the
timeSetEventAPI (a completely non-intuitive API name, I know). Use a callback function and theTIME_ONESHOTparameter.