Click to See Complete Forum and Search --> : Log parser reading lines twice


ckozak
January 10th, 2005, 03:14 PM
I have a log file parser that is looking for file size change notifications. Sometimes though it will read the new line(s) twice which is a mystery to me.


unsigned __stdcall MonitorThreadProc(LPVOID lpThreadParam)
{

DWORD dwThreadID = GetCurrentThreadId();
DWORD dwWaitStatus;
HANDLE dwChangeHandle[2];

CStdioFile logFile(g_strFile, CFile::modeRead | CFile::shareDenyNone);
CString line;
CParseFunctions parse;

logFile.SeekToEnd();

g_pSettings->SetMonitorStatus(true);

dwChangeHandle[0] = FindFirstChangeNotification(
g_strFile, // directory to watch
FALSE, // do not watch the subtree
FILE_NOTIFY_CHANGE_SIZE); // watch file size changes


dwChangeHandle[1] = theApp.m_hQuitEvent;

if (dwChangeHandle == INVALID_HANDLE_VALUE)
ExitProcess(GetLastError());

while (TRUE)
{
// Wait for notification.
dwWaitStatus = WaitForMultipleObjects(2,dwChangeHandle,FALSE, INFINITE);

switch (dwWaitStatus)
{
case WAIT_OBJECT_0:

if (logFile.ReadString(line) ){
parse.ParseLine(line);
::PostMessage(g_pParserStats->m_hWnd,PARSER_STATS_UPDATE,NULL,NULL);
}

while( FindNextChangeNotification(dwChangeHandle) )
{
if (logFile.ReadString(line) ){
parse.ParseLine(line);
::PostMessage(g_pParserStats->m_hWnd,PARSER_STATS_UPDATE,NULL,NULL);
}
}
break;

case WAIT_OBJECT_0 + 1:
FindCloseChangeNotification(dwChangeHandle[0]);
return(dwThreadID);;
break;

default:
return dwThreadID;
}
}


logFile.Close();

return dwThreadID;


}




Any ideas as to why it might read lines twice?