Skip to content

Instantly share code, notes, and snippets.

@tpetrina
Created July 30, 2012 21:02
Show Gist options
  • Save tpetrina/3210186 to your computer and use it in GitHub Desktop.
Save tpetrina/3210186 to your computer and use it in GitHub Desktop.
Asynchronous file loading for Metro styled applications using DirectX/C++
inline Concurrency::task<Platform::String^> ReadStringAsync(Platform::String^ filename)
{
using namespace Windows::Storage;
using namespace Concurrency;
auto folder = Windows::ApplicationModel::Package::Current->InstalledLocation;
task<StorageFile^> getFileTask(folder->GetFileAsync(filename));
auto readBufferTask = getFileTask.then([] (StorageFile^ f)
{
return FileIO::ReadBufferAsync(f);
});
auto byteArrayTask = readBufferTask.then([] (Streams::IBuffer^ b) -> Platform::String^
{
return Streams::DataReader::FromBuffer(b)->ReadString(b->Length);
});
return byteArrayTask;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment