I use next code to know when a files is changed in a certain folder:
HANDLE hDir = ::CreateFile(path, FILE_LIST_DIRECTORY, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS|FILE_FLAG_OVERLAPPED, NULL);
FILE_NOTIFY_INFORMATION returnData[1024];
DWORD returnDataSize = 0;
while(ReadDirectoryChangesW(hDir, returnData, sizeof(returnData), TRUE, FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_DIR_NAME|FILE_NOTIFY_CHANGE_LAST_WRITE, &returnDataSize, NULL, NULL))
{
...
}
ReadDirectoryChangesW blocks the thread until a file changes occurs. Is there any way to stop/force return from this function?
From your description, it sounds like
CancelIoExshould do the trick. Obviously, you need another thread for that, since you’re now calling it synchronously. That blocks the calling thread, so you can’t do anyting from that thread, not even stop.