Holy cow, I wrote a book!
Many people have noticed that the
(and therefore their BCL equivalent
and WinRT equivalent
when you save a file in Notepad.
Why is that?
Because multiple things were modified.
Notepad opens the file for writing, writes the new data,
calls SetEndOfFile to truncate
any excess data (in case the new file is shorter than the old file),
then closes the handle.
Two things definitely changed, and a third thing might have changed.
It's therefore not surprising that you got two events,
the original design goals of the
It's for letting an application cache a directory listing and update
Given these design goals,
filtering out redundant notifications in the kernel
is not required aside from
the performance benefits of reduced chatter.
report a spurious change every 5 seconds,
and the target audience for the function would still function
correctly (albeit suboptimally).
Given this intended usage pattern, any consumer of
ReadDirectoryChangesW needs to accept
that any notifications you receive encompass the minimum information
you require in order to keep your cached directory information
up to date,
but it can contain extra information, too.
If you want to respond only to actual changes,
you need to compare the new file attributes against the old ones.
Actually, the two things that changed when Notepad
set the file size are
the allocation size and the file size
(which you can think of as the physical and logical file sizes,
Internally, this is done by two separate calls into the I/O manager,
so it generates two change notifications.