I want to perform the action at a certain timeout, like fire an
event. I figured out how to do every n number of seconds, but not 1.5
seconds. Here is what I have. Please suggest how to handle my case:
void Publish()
{
static int local_time=time(NULL);
int current_time = time (NULL);
if((current_time+PUBLISH_TIMEOUT)>local_time)
{
fireEvent();
local_time=current_time;
}
}
This returns the wall time since the application started in millisecs. It uses the machines clock so it is quite possible that changing the clock’s time while the app is running will confuse it. In your case I would add a schedule time to my event object and fire when schedule time <= msec()