Original Post
I am having trouble with this one thread in my program and thought maybe someone could help me....Here is the code and i''ll explain it :
unsigned __stdcall CtlFileTimeLoop(void *)
{
HANDLE hTermOrThread[2] = {NULL}, TellWhenReceivedEvent = NULL;
UINT ThreadId = 0;
DWORD TimeLeft = 0, test = 0;
BOOL NowTerm = FALSE;
char INIPath[MAX_PATH], Msg[500];
FLAG Results = 0;
GetPath(INIFileName, INIPath);
if(INVALID_HANDLE_VALUE == (hTermOrThread[0] = FindFirstChangeNotification(INIPath, FALSE, FILE_NOTIFY_CHANGE_LAST_WRITE)))
{
Logging(GetLastError(), __LINE__);
}
if(USED_DEFAULT &(Results = ReadINIFile(TERMINATE, Term, 4)))
{
strcpy(Msg, "Using default for termination which is ");
strcat(Msg, Term);
strcat(Msg, "Process will continue\n");
Logging(USED_DEFAULT, Msg);
}
AllToUpper(Term);
while(strcmp("YES", Term))
{
if(SetMyTimer(1 * ONE_SYSTEM_MINUTE, CHECK_TIME_OUT, &TimeLeft))
{
if(NULL == (hTermOrThread[1] = reinterpret_cast(_beginthreadex(NULL, 0, CtlFileLoop, NULL , 0, &ThreadId))))
{
Logging(GetLastError(), __LINE__);
}
SetMyTimer(atol(WaitTime) * ONE_SYSTEM_MINUTE, SET, &TimeLeft);
}
else
{
SetMyTimer(atol(WaitTime) * ONE_SYSTEM_MINUTE, SET, &TimeLeft);
}
if(hTermOrThread[1] == NULL)
{
test = WaitForSingleObject(hTermOrThread[0], ONE_SYSTEM_MINUTE);
}
else if(WAIT_OBJECT_0 == WaitForSingleObject(hTermOrThread[1], 0))
{
CloseHandle(hTermOrThread[1]);
hTermOrThread[1] = NULL;
test = WaitForSingleObject(hTermOrThread[0], ONE_SYSTEM_MINUTE);
}
else
{
test = WaitForMultipleObjects(2, hTermOrThread, FALSE, INFINITE);
SetMyTimer(atol(WaitTime) * ONE_SYSTEM_MINUTE, SET, &TimeLeft);
}
}
WaitForSingleObject(hTermOrThread[0], INFINITE);
CloseHandle(hTermOrThread[0]);
CloseHandle(hTermOrThread[1]);
return 0;
}
BOOL SetMyTimer(DWORD Delay, FLAG Settings, DWORD *TimeLeft)
{
static DWORD StartTime = 0;
BOOL TimeOut = FALSE;
if(SET & Settings)
{
StartTime = GetTickCount();
TimeOut = FALSE;
*TimeLeft = Delay;
}
if(CHECK_TIME_OUT & Settings)
{
TimeOut = ((*TimeLeft = GetTickCount()) - Delay) > StartTime ? TRUE : FALSE;
*TimeOut = TimeOut ? StartTime - *TimeLeft;
}
return TimeOut;
}
All this program does it go into the thread CtlFileLoop and every minute go into the thread. For some reason, she goes into the thread the first time and never goes into it again and I don''t get an error at all. I would be very thankful if someone could help.
braves