Created
July 30, 2012 21:02
-
-
Save tpetrina/3210186 to your computer and use it in GitHub Desktop.
Asynchronous file loading for Metro styled applications using DirectX/C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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