Re: Monitor a directory using WaitForMultipleObjects
Ganga Sridhar <gangasridhar@abosoftware.com> wrote:
My code does some what the same as what you have suggested i.e.
FindFirstChangeNotification before the while(wait), then the FindNext
for each directory after the Wait. Basically the FindNext function is
a part of another function of a different class , I have included it
for your reference this time.
My problem is a bit more complex as I am not monitoring a single
directory but a list of directories, so I believe there will
definitely be a lapse between the directories.
Well, if your goal is to take a snapshot of a content of a list of
directories at a particular point in time, I believe it's impossible.
Moreover, it's impossible even for a single directory. New files may be
added and old files removed while you are iterating over the contents.
If all you want is to be notified of new files soon after they were
added, then handling a list of directories is not much different from
handling one. Just open multiple handles with
FindFirstChangeNotification, use WaitForMultipleObjects on them, and
call FindNextChangeNotification immediately after Wait* _on the handle
that satisfied the wait_. The important part is to call
FindNextChangeNotification on a handle referring to a particular
directory _before_ you start looking at the contents of said directory.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925