AsyncOperation变成同步的代码

template <typename TResult>
TResult PerformSynchronously(Windows::Foundation::IAsyncOperation<TResult>^ asyncOp)
{
Concurrency::event synchronizer;
Concurrency::task<TResult>(asyncOp).then([&](TResult taskResult) {
synchronizer.set();
}, Concurrency::task_continuation_context::use_arbitrary());
synchronizer.wait();
return asyncOp->GetResults();
}

用法:

ContactStore^ store = PerformSynchronously(ContactManager::RequestStoreAsync());
IVectorView<Windows::ApplicationModel::Contacts::Contact^>^ contacts = PerformSynchronously(store->FindContactsAsync(“123123”));

上一篇:Electron中使用sql.js操作SQLite数据库


下一篇:IE插件收集