private async void Query_ContentsChanged(IStorageQueryResultBase sender, object args) { // Run on UI thread. await App.Current.NavigationService.Frame.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { var tracker = _folder.TryGetChangeTracker(); if (tracker != null) { var changeReader = tracker.GetChangeReader(); var changes = await changeReader.ReadBatchAsync(); foreach (var change in changes) { if (change.ChangeType == StorageLibraryChangeType.ChangeTrackingLost) { // Change tracker is in an invalid state and must be reset // This should be a very rare case, but must be handled tracker.Reset(); return; } if (change.IsOfType(StorageItemTypes.File)) { // Process file change on UI thread. await ProcessFileChange(change); } else if (change.IsOfType(StorageItemTypes.Folder)) { // No-op; not interested in folders } else { if (change.ChangeType == StorageLibraryChangeType.Deleted) { // TODO: The application does not have to support FAT drives at the moment. NTFS is enough. //UnknownItemRemoved(change.Path); } } } // If any changes were recorded, save database. if (changes.Count > 0) { // Log query contens changed saving. GalleryLog.QueryContentsChangedSaving(); await DatabaseUtils.SaveAllMetadatasAsync(MediaDatas); } await changeReader.AcceptChangesAsync(); } }); }