- 10


hProc();

__try {

WaitForSingleObject(hConfigMutex, INFINITE);

((struct TASKENTRY*)ThreadParm)->Active = FALSE;

CloseHandle((HANDLE)((struct TASKENTRY*)ThreadParm)->TaskThread);

}

__finally {

ReleaseMutex(hConfigMutex);

}

} else LogEvent(EVENTLOG_ERROR_TYPE, "Error Getting Procedure Address");

} else LogEvent(EVENTLOG_ERROR_TYPE, "Error Getting TermProc Address");

} else {

ReleaseMutex(hConfigMutex);

LogEvent(EVENTLOG_ERROR_TYPE, "Error Loading Library");

}

InterlockedDecrement(&TaskCount);

return 0;

}

void AnalyseTaskTable()

{

DWORD CurrTime;

int i;

CurrTime = GetTimeInMins();

__try {

WaitForSingleObject(hConfigMutex, INFINITE);

for (i = 0; i < EntryCount; i++) {

if ((TaskTable[i].ExecTime == CurrTime) &&

(!TaskTable[i].Active)) {

CreateThread(NULL, 0, TaskProc, &TaskTable[i], 0, &TaskTable[i].TaskThread);

}

}

}

__finally {

ReleaseMutex(hConfigMutex);

}

}

DWORD GetTimeInMins()

{

SYSTEMTIME SysTime;

GetLocalTime(&SysTime);

return SysTime.wHour*60+SysTime.wMinute;

}

void TerminateTasks()

{

int i;

DWORD TaskIndex = 0;

HANDLE Handles[TASK_COUNT];

for (i = 0; i < EntryCount; i++) {

if (TaskTable[i].Active) {

TaskTable[i].TermProc();

Handles[TaskIndex++] = (HANDLE)TaskTable[i].TaskThread;

}

}

WaitForMultipleObjects(TaskIndex, Handles, TRUE, INFINITE);