Every 12 seconds have a software, a file to a directory do WriteFile operation, the first in a offset WriteFile an increasing timestamp, after in the offset of the WriteFile other content, the last call FlushFileBuffer, this one minute to write five times, with the process monitor to monitor, as shown in the figure below:
Increasing red box part is to write the timestamp of the operating
My task is to monitor the software of the directory of this file each time update, and then parse the file content, sent out,
I use the API is ReadDirectoryChangesW () combined with complete routines, to monitor the directory of the file, if the files in the directory update response is complete routines (callback function), Specific methods, refer to a lot of examples, should be no problem, at the same time, the callback function response times and five times a minute, this is no problem, that is to say, the change of the file, is to monitor
The software every time a location on the file written to increasing timestamp, normal should be
.
The NTH file change response, and then read the file, read the timestamp is 20180503143009 N + 1 times file change response, then read files, read the timestamp is 20180503143021
.
But always there
.
The NTH file change response, and then read the file, read the timestamp is 20180503143009 N + 1 times file change response, then read files, read the timestamp is 20180503143009
.
Or
.
The NTH file change response, and then read the file, read the timestamp is 20180503143021 N + 1 times file change response, then read files, read the timestamp is 20180503143021
.
That is to say, every monitor to file change after, I went to read the timestamp of part of file's contents, the timestamp should be incremented, arguably, monitoring to the file after the change, write operations should be flush to disk before, this should not happen,
I wonder if the ReadDirectoryChangesW () mechanism, the best is only the change of the notice to the file, but does not guarantee that after receiving callback notice, content is thoroughly was FlushFileBuffer to disk,