locked
Folder monitor using contentschanged event listener RRS feed

  • Question

  • Dear All:

    I have a problem on "contentschanged" event firing.

    I was using this event for monitoring the specified folder like:

    var fileQuery = null; function init() { Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.getFolderAsync(entry.token).then(function (folder) { fileQuery = folder.createFileQuery(); fileQuery.getFilesAsync().then(function (files) { ... ... // Get original file in the specified folder }).then(function () { fileQuery.addEventListener("contentschanged", contentChanged); }); }, function (error) { }); } function contentChanged(eventObject) { var entry = Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.entries[0]; Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.getFolderAsync(entry.token).then(function (folder) { // Set the event handler of media folder content changed fileQuery = folder.createFileQuery(); fileQuery.getFilesAsync().then(function (files) { ... ... // Compare files in the specified folder (which added or removed)

    }).then(function () { fileQuery.addEventListener("contentschanged", contentChanged); }); }); };

    The initial function: init() was called after App was loaded. Is it essntial that to reset fileQuery and  contentschanged event listener?  Another problem is when I modify large number of files in this folder, maybe greater than 200 files, the contentschanged event fires randomly... Rarely to fire this event... But for small number of files, the event almost fires...

    Rarely to find such sample using contentschanged event...

    Thanks for helps...

    Tuesday, November 20, 2012 5:46 AM

Answers

  • This event is unreliable, unfortunately. It also gives you not enough information about the changes that happened. Who knows when and how it fires... I think we are better off with manual polling at an interval for now.
    • Marked as answer by UOW_Nick Tuesday, November 27, 2012 2:10 AM
    Tuesday, November 20, 2012 11:10 AM

All replies

  • Dear All:

    I have a problem on "contentschanged" event firing.

    I was using this event for monitoring the specified folder like:

    var fileQuery = null; function init() { Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.getFolderAsync(entry.token).then(function (folder) { fileQuery = folder.createFileQuery(); fileQuery.getFilesAsync().then(function (files) { ... ... // Get original file in the specified folder }).then(function () { fileQuery.addEventListener("contentschanged", contentChanged); }); }, function (error) { }); } function contentChanged(eventObject) { var entry = Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.entries[0]; Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.getFolderAsync(entry.token).then(function (folder) { // Set the event handler of media folder content changed fileQuery = folder.createFileQuery(); fileQuery.getFilesAsync().then(function (files) { ... ... // Compare files in the specified folder (which added or removed)

    }).then(function () { fileQuery.addEventListener("contentschanged", contentChanged); }); }); };

    The initial function: init() was called after App was loaded. Is it essntial that to reset fileQuery and  contentschanged event listener?  Another problem is when I modify large number of files in this folder, maybe greater than 200 files, the contentschanged event fires randomly... Rarely to fire this event... But for small number of files, the event almost fires...

    Rarely to find such sample using contentschanged event...

    Thanks for helps...

    Additional question: A quite strange problem...If I test the contentschanged event just after project run, event may be fired normally, and in Task Manager, the task Runtime Broker uses more memory. But...if I did something else without moving files in folder, maybe 1 min, and then add files in this folder, the contentschanged event is disabled to fire...

    Tuesday, November 20, 2012 9:41 AM
  • This event is unreliable, unfortunately. It also gives you not enough information about the changes that happened. Who knows when and how it fires... I think we are better off with manual polling at an interval for now.
    • Marked as answer by UOW_Nick Tuesday, November 27, 2012 2:10 AM
    Tuesday, November 20, 2012 11:10 AM
  • I found that any getFilesAsync process of the specified folder should register the handler of contentschanged event again and all processes use the same fileQuery variable. Is it right or not?


    • Edited by UOW_Nick Thursday, November 22, 2012 1:32 AM
    Thursday, November 22, 2012 1:31 AM
  • For StorageFolderQueryResult.ContentsChanged:

    Is there any usage limitation that only need to call GetFilesAsync at least once? If I got the query of a specified folder, and I want to use such event to monitor the specified folder during the App run. Also, maybe I need to call GetFilesAsync within the event handler function for comparing what files were added or deleted, or modified etc. So, is it essential that I should reset the query variable to call GetFilesAsync? If not, the event would be available or not? ...

    Besides, maybe my project requires to reset the query with other options...Is there anything else to do?...

    confused...

    Thursday, November 22, 2012 8:30 AM
  • Thanks phil.

    I think that way would be better...

    Tuesday, November 27, 2012 2:10 AM