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”));
原文地址:http://www.cnblogs.com/codefinder/p/3996519.html