当我调用GetFolderFromPathAsync

时间:2017-03-29 03:32:59

标签: uwp

我的应用程序完全冻结后才有机会运行一次。这是上下文: 我正在构建一个UWP应用程序,它将与用户目录一起使用,监视其中的文件,并在UI控件中列出它们。我通过创建手动文件夹选择提示将目录添加到futureaccess列表。我还有一个服务类,它应该给我一个驻留在该目录中的文件列表。一旦我到达GetFolderFromPathAsync方法,该应用程序就会冻结。没有异常或任何类型的错误,应用程序尝试启动并无限期地处于启动过程中。 这是调用方法的类:

public class ReplayDirectoryManager
{
    public async static Task<List<StorageFile>> GetAllReplaysFromReplayDirectory()
    {
        string replayDirectoryPath = SettingsServices.SettingsService.Instance.ReplayFolderLocation;
        StorageFolder replayFolder = await StorageFolder.GetFolderFromPathAsync(replayDirectoryPath);

        return new List<StorageFile>(await replayFolder.GetFilesAsync());
    }
}

如何让我的代码工作?有什么建议吗?

以下是我用于将位置添加到futureaccess列表的代码

FolderPicker picker = new FolderPicker();
picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
picker.FileTypeFilter.Add("*");
StorageFolder folder = await picker.PickSingleFolderAsync();
if (folder != null)
{
    Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(folder);
    ReplayFolderLocation = folder.Path;
}

1 个答案:

答案 0 :(得分:0)

使用Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(folder);时,您可以获得令牌。

您可以使用保存令牌进行设置。

您可以通过令牌获取文件夹

folder =  await StorageApplicationPermissions.FutureAccessList.GetFolderAsync(token);

@Romasz Thx。

相关问题