locked
File access times stop being modified after FindFirstChangeNotification? RRS feed

  • Question

  • Sorry if I'm vague here, but the code is kind of complex. I'm using FindFirstChangeNotification + FindNextChangeNotification in a thread to watch a directory for changes (to file write times and file name changes). When I detect a change, I use CreateFile to open a specific file that I'm watching, GetFileTime to get it's last access time, I check to see if the access time has been changed, and if so, I process the changed file.

    The file is always closed when I'm done looking at it. I've verified this. When I'm finished I call FindCloseChangeNotification. I verified this as well. I've also verified that all operations are succeeding. Sometimes, the application re-initializes the file monitor, and so it closes all the handles, cleans up, then creates new change notifications from scratch again.

    The problem I first noticed is after about the third or fourth time this re-initialization happens, I stop receiving change notifications for the directory when the file changes. I can't reproduce this in an isolated test case, which is why I didn't post any code. I'm quite sure it's because of something else that's happening in the program, but I have no idea what.

    When I investigated, however, much to my surprise, I found that the notifications seem to be being missed on a much lower level than in my application. When I modify the file and save it, not only do I not receive a directory change notification, but GetFileTime() never returns the new write access time. The last write time never changes. Digging deeper, I looked at the file properties in an explorer shell window, and lo and behold, the access time is not changing! I can modify the file, save it, and the access time will *not* change in explorer, but the file changes will be correctly written! Not only does the access time not change, but the system is never notified that the file has changed. This effect only lasts until I exit my application, at which point the access time is correctly updated on save again.

    My question is, to help me narrow down the cause: What kinds of things would prevent Windows from updating the last access time of a file when the file is saved? What kinds of things could I be doing in my application that may cause that to happen? It appears that something that I'm doing is interfering at the system level with file time updates, although I might be misinterpreting what I'm seeing?

    I'm having a really hard time narrowing this down.

    Thanks,
    J
    Tuesday, December 16, 2008 8:35 PM