locked
Why is ReadDirectoryChangesW not allowed in WinRT apps? RRS feed

  • General discussion

  • I really have to wonder... the provided change notifications in WinRT are crap. They do not offer any way to find out what has been actually changed. This is so annoying since ReadDirectoryChangesW, which is most likely internally used to watch for file/folder changes, offers plenty of information about a change. Why did the implementers of the FileQuery.onchange notifier decided to omit almost all vital informations in the change event they give to us WinRT users?

    It seems the SkyDrive app also suffers from this limitation heavily. Try opening and changing a picture from within the SkyDrive app using an external (MS Paint) desktop program. Changes made to files will not be up-synced. This of course renders the SkyDrive app totally useless with this unexpected behaviour. Its merely a reader/browser now.

    MS should really rethink this issue. Dropbox will have the same problems I guess.

    Tuesday, November 20, 2012 10:59 AM

All replies

  • Hi Phil,

    Not everything in Win32 was ported to WinRT.  What is your specific scenario and what are you using the information for?  Perhaps I can help.

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, November 21, 2012 8:54 PM
    Moderator
  • The scenario is to watch a folder and get notified if files / folders in that folder are changed. That is renamed, deleted, created or modified.

    The ReadDirectoryChangesW gives us all this with almost 0 CPU impact on Win32. The WinRT FileQuery onchanged event gives us nothing. Only that something has changed. We would then have to reparse the folder and subfolders again and diff the files according to there previous state.

    I am currently playing with AQS to get at least only the files that have been changed since a specific point in time.

    Wednesday, November 21, 2012 9:10 PM
  • Hi Phil,

    What is the purpose of your app?  Why do you need this information?  Specifically what will you do when a file is renamed, deleted, created, modified?

    -Jeff


    Jeff Sanders (MSFT)

    Wednesday, November 21, 2012 9:22 PM
    Moderator
  • Lets assume my app is a dropbox client. When a file is changed/added/deleted I will sync that with the server.
    Thursday, November 22, 2012 9:29 AM
  • Hi Phil,

    To make a long spec short...

    Rather than watching for FileChange, you should look to FolderChange for these events.  Continuous polling of file status is indeed costly in terms of CPU and power.  The recommended approach and that taken of other apps that need this functionality is to keep a local DB of file state and during the initialization of the UI or when you return to the app from another app to act on changes.  For example, you may get a bunch of notifications of add, delete etc... but only act on them periodically.  That frequency of update is left to you, but you should consider only updating/syncing periodically. 

    Of course there are tradeoffs to this approach but once you understand the model you should be able to get your head around this and see the benefit.  No, this is not the same as Win32 but you can accomplish the same thing.  This is the model that the Music app uses to track media.

    HTH

    -Jeff


    Jeff Sanders (MSFT)

    Monday, November 26, 2012 2:26 PM
    Moderator
  • I checked the Music app, it does not use those events. Beside there are no notification of the kind "add, delete..." Thats what I am saying all the time. You have to figure out yourself if it was an add,delete or change notification.

    Where does the music app do that?

    Tuesday, November 27, 2012 5:31 PM
  • Correct, I was not implying that you get an add, delete just that those actions will result in the event firing.  Yes, you have to do this for yourself.

    Jeff Sanders (MSFT)

    Tuesday, November 27, 2012 7:53 PM
    Moderator
  • One day I will come up with a nice wrapper around this limitation. Hopefully others will not suffer from the same issues then.
    Tuesday, November 27, 2012 8:33 PM