我有一个简单的线程,可以监视文件的更改。
UINT CFileMonitoringManager::WaitingOnChanges(LPVOID lpParam)
{
CFileMonitoringManager *pThisClass = (CFileMonitoringManager*)lpParam;
TCHAR szFileNameBuffer[MAX_PATH];
DWORD dwBytes = 0;
DWORD cbOffset = 0;
CSubscribeTarget *pObject = NULL;
LPOVERLAPPED lpOverlapped = NULL;
FILE_NOTIFY_INFORMATION *pNotifyInfo = NULL;
while(pThisClass->m_hCompPort)
{
if (::GetQueuedCompletionStatus(pThisClass->m_hCompPort, &dwBytes, (LPDWORD)&pObject, &lpOverlapped, INFINITE))
{
pNotifyInfo = (PFILE_NOTIFY_INFORMATION)pObject->m_NotifyBuffer;
DWORD dwBytesRead = 0;
memset(szFileNameBuffer, 0, sizeof(TCHAR) * MAX_PATH);
TCHAR* szFileName =
GetTCHAR(pNotifyInfo->FileName, pNotifyInfo->FileNameLength, szFileNameBuffer, MAX_PATH);
//My custom code
if(!pObject->ReadingDirectory())
return 0;
}
}
return 0;
}
我正在使用ReadDirectoryChangesW
和CreateIoCompletionPort
。
我有情况:
当我订阅D:\ TESTS \ INPUT.txt并更改D:\ TESTS \ INPUT2.txt时,我得到普通名称INPUT.txt和长度为20的那些变量
pNotifyInfo->FileName, pNotifyInfo->FileNameLength
我跳过我的特殊文件代码并重新开始等待。当我更改D:\ TESTS \ INPUT.txt(我订阅的文件)时,我进入INPUT.txtt,18进入那些变种
pNotifyInfo->FileName, pNotifyInfo->FileNameLength
怎么了?我无法理解。有几次它开始返回正常数据。 请帮帮我