【发布时间】:2019-02-24 21:30:37
【问题描述】:
我想将作业分派到 UI 线程,然后等待结果并从另一个线程使用它。像这样,但是 co_await 在 lambda 中不起作用:
dispatcher.RunAsync(CoreDispatcherPriority::Normal, [&]() {
auto res = co_await mStoreContext.RequestPurchaseAsync(L"");
});
或者甚至等待整个 RunAsync 操作,如果我能从中得到我的结果
【问题讨论】:
-
更惯用的方式是
co_await resume_foreground(dispatcher); auto res = co_await mStoreContext.RequestPurchaseAsync(L""); co_await resume_background(); use_result(res);
标签: c++ multithreading concurrency async-await winrt-async