I don't have any problems, but just wanted to share what I thought might be a useful piece of code. Sometimes, doing something asynchronously is just not desirable. This function will cause an asynchronous operation to be performed asynchronously - blocking
the current thread till it completes.
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();
}
Here's an example of use:
Platform::String^ ResourcePath(Platform::String^ fileName)
{
Windows::ApplicationModel::Resources::Core::ResourceCandidate^ resCandidate;
resCandidate = Windows::ApplicationModel::Resources::Core::ResourceManager::Current->MainResourceMap->GetSubtree("Files")->GetValue(fileName);
Windows::Storage::StorageFile^ storageFile = PerformSynchronously(resCandidate->ToFileAsync());
return storageFile->Path;
}
I originally posted this as an edit in
another thread.