我想向 UI 线程分派(dispatch)一个作业,然后等待结果并从另一个线程使用它。像这样,但是 co_await 在 lambda 内部不起作用:
dispatcher.RunAsync(CoreDispatcherPriority::Normal, [&]() {
auto res = co_await mStoreContext.RequestPurchaseAsync(L"");
});
或者甚至等待整个 RunAsync 操作,如果我能从中得到结果的话
最佳答案
那是因为void
不能用作协程的返回值(我可以,如果你使用我的 my library )。
尝试返回 std::future<void>
相反:
dispatcher.RunAsync(CoreDispatcherPriority::Normal, [&]() -> std::future<void> {
auto res = co_await mStoreContext.RequestPurchaseAsync(L"");
});
关于c++ - winrt/c++ : await result from dispatched task,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52427339/