从 FutureAccessList 同步获取文件夹路径

Get Folder Path Synchronously from FutureAccessList

本文关键字:文件夹 路径 获取 同步 FutureAccessList      更新时间:2023-10-16

我使用FolderPicker在FutureAccessList中存储了许多文件夹。出于日志记录/配置目的,我希望能够枚举这些并将其完整路径打印为字符串。

我已经编写了下面的代码来尝试帮助解决这个问题,但它不断抛出以下内容:

Unhandled exception at 0x0355CAB6 (ucrtbased.dll) in foo.exe: An invalid 
parameter was passed to a function that considers invalid parameters fatal.

这是代码,如果有人能告诉我哪里出错了,我将不胜感激。真的我想以同步方式执行 GetFolderAsync 函数,即 exec-wait-return。我确定有一个简单的答案,但我只是在加快C++/UWP 编程的速度,这些编程具有其他语言的背景!

String^ MainPage::GetFolderPathForKey(String^ key)
{
    task<String^> t = create_task(
        StorageApplicationPermissions::FutureAccessList->GetFolderAsync(key))
        .then([](StorageFolder^ folder)
    {
        if (folder != nullptr) {
            return folder->Name;
        }
        return ref new String(L"Unknown?");
    });
    String^ taskResult = t.get();
    return taskResult;
}

问题是由于在 UI 线程中尝试 get((/wait(( 引起的。