I want to monitor folder for recursive changes. I use this code:
public async void StartMonitor(string folderPath)
{
StorageFolder storageFolder = await StorageFolder.GetFolderFromPathAsync(folderPath);
QueryOptions queryOptions = new QueryOptions();
queryOptions.FolderDepth = FolderDepth.Deep;
StorageItemQueryResult query = storageFolder.CreateItemQueryWithOptions(queryOptions);
query.ContentsChanged += QueryContentsChanged;
await query.GetItemsAsync();
}
private void QueryContentsChanged(IStorageQueryResultBase sender, object args)
{
//to do
}
Event is fired once after StatMonitor executes. But then when I create file or folder in this directory, event is not fired. How can I get this event firing?
The query object was going out of scope. I made the query object a private class field and it works.