MyKidsDiary.in :: Capture your kids magical moment and create your Online Private Diary for your kids
void CSchedule::startLoop()
{
if(m_bIsRunning) return;
m_bIsRunning = true;
AfxBeginThread(ScheduleThreadProc, this);
}
UINT ScheduleThreadProc( LPVOID pParam )
{
CSchedule* pSchedule = (CSchedule*)pParam;
POSITION pos;
int ID;
CAlarm* pAlarm;
CTime curTime;
while(pSchedule->isRunning()) {
if(pSchedule->m_mapAlarms.IsEmpty())
continue;
curTime = CTime::GetCurrentTime();
pos = pSchedule->m_mapAlarms.GetStartPosition();
while(pos!=NULL) {
pSchedule->m_mapAlarms.GetNextAssoc(pos, ID, pAlarm);
// pAlarm->getTimeSpan() should be 0 in single alarms
if(pAlarm->getTime() + pAlarm->getTimeSpan() <= curTime) {
if(pAlarm->isEnabled())
pAlarm->fire();
pAlarm->setTime(pAlarm->getTime() + pAlarm->getTimeSpan());
if(pAlarm->isSignle()) {
delete pAlarm;
pSchedule->m_mapAlarms.RemoveKey(ID);
}
}
}
}
return 0;
}