删除多个文件时UWP StorageLibraryContentChangedTrigger

UWP StorageLibraryContentChangedTrigger when deleting multiple files

我正在使用 BackgroundTask 跟踪我的图片库中的文件和文件夹更改。这很好用,但是当我一次删除多个文件时,BackgroundTask 不会触发。

这是我的 BG 任务注册

private async void RegisterTask()
{
    var result = await BackgroundExecutionManager.RequestAccessAsync();
    var builder = new BackgroundTaskBuilder();

    builder.Name = taskName;
    builder.TaskEntryPoint = taskEntryPoint;

    StorageLibrary picturesLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Pictures);
        StorageLibraryContentChangedTrigger libraryTrigger = StorageLibraryContentChangedTrigger.Create(picturesLibrary);

    builder.SetTrigger(libraryTrigger);
    builder.Register();
}

这是我的简单测试 BG-Task

public async void Run(IBackgroundTaskInstance taskInstance)
{
    var deferral = taskInstance.GetDeferral();

    try
    {
        await DoWork();
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine("ERROR BG: " + ex.Message.ToString());
    }

    deferral.Complete();
}

最后是我的 DoWork() 任务

private async Task DoWork()
{
    StorageLibrary picturesLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Pictures);
    StorageLibraryChangeTracker picturesTracker = picturesLibrary.ChangeTracker;
    picturesTracker.Enable();
    StorageLibraryChangeReader changeReader = picturesTracker.GetChangeReader();
    IReadOnlyList<StorageLibraryChange> changes = await changeReader.ReadBatchAsync();

    foreach (StorageLibraryChange change in changes)
    {
        // Reading the changes
    }

    await changeReader.AcceptChangesAsync();
}

我错过了什么吗?当只删除一个文件时,BackgroundTask 会被成功触发,但是当我从我的图片库中一次删除多个文件时不会。

此致

Did i miss something? When deleting only one file, the BackgroundTask will be triggered successfully, but not when i delete multiple files at once from my PicturesLibrary

目前的行为是,删除多个文件时,更改记录会顺延到下一次更改的记录。

比如我们删除了两个文件后,新建了一个文件,任务被触发,删除的修改包含在StorageLibraryChange列表中:

[2/28/2017 4:52:35 PM] Background LibFileChangeTask Start 
Path: C:\Users\xxxx\Pictures.txt
ChangeType: Deleted
Path: C:\Users\xxxx\Pictures.txt
ChangeType: Deleted
Path: C:\Users\xxxx\Pictures\New Text Document.txt
ChangeType: Created

我们已经提交了这个问题,相关团队正在煽动它。