码迷,mamicode.com
首页 > 其他好文 > 详细

AsyncOperation变成同步的代码

时间:2014-09-27 18:25:50      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:io   ar   for   sp   on   c   代码   amp   r   

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”));

 

AsyncOperation变成同步的代码

标签:io   ar   for   sp   on   c   代码   amp   r   

原文地址:http://www.cnblogs.com/codefinder/p/3996519.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!