task ReadContent(String^ filename) { anim->Start(); auto t = create_task(KnownFolders::DocumentsLibrary-> GetFileAsync(filename)).then( [](StorageFile^ file) { return file->OpenAsync(FileAccessMode::Read); }).then( [](IRandomAccessStream^ stream) { auto inputStream = stream->GetInputStreamAt(0); auto dr = ref new DataReader(inputStream); return dr->LoadAsync(stream->Size); }).then( [anim](unsigned int count) { anim->End(); // read content return content; }); return t; } Async & Exceptions
anim->Start(); auto t = create_task(KnownFolders::DocumentsLibrary-> GetFileAsync("Log.txt")).then( [](StorageFile^ file) { return file->OpenAsync(FileAccessMode::Read); }).then( [](IRandomAccessStream^ stream) { auto inputStream = stream->GetInputStreamAt(0); auto dr = ref new DataReader(inputStream); return dr->LoadAsync(stream->Size); }).then( [anim](unsigned int count) { anim->End(); // read content }); return t; [anim](unsigned int count) { anim->End(); // read content }); Async & Exceptions [anim](task lt) { anim->End(); // read content }); [anim](task lt) { anim->End(); try { unsigned int count = lt.get(); // read content } catch(AccessDeniedException^ ex) { throw; } });
void MainPage::OnNavigatedTo(NavigationEventArgs^ e) { create_task(KnownFolders::DocumentsLibrary-> GetFileAsync(“Surface.ini")).then( [](StorageFile^ file) { return file->OpenAsync(FileAccessMode::Read); }).then( [](IRandomAccessStream^ stream) { auto inputStream = stream->GetInputStreamAt(0); auto dr = ref new DataReader(inputStream); return dr->LoadAsync(stream->Size); }).then( [](unsigned int count) { // read content txtContent->Text = content; }); }
void MainPage::OnNavigatedTo(NavigationEventArgs^ e) { create_task(KnownFolders::DocumentsLibrary-> GetFileAsync(“Surface.ini")).then( [](StorageFile^ file) { return file->OpenAsync(FileAccessMode::Read); }).then( [](IRandomAccessStream^ stream) { auto inputStream = stream->GetInputStreamAt(0); auto dr = ref new DataReader(inputStream); return dr->LoadAsync(stream->Size); }).then( [](unsigned int count) { // read content txtContent->Text = content; }); }
void MainPage::OnNavigatedTo(NavigationEventArgs^ e) { create_task(KnownFolders::DocumentsLibrary-> GetFileAsync(“Surface.ini")).then( [](StorageFile^ file) { return file->OpenAsync(FileAccessMode::Read); }).then( [](IRandomAccessStream^ stream) { auto inputStream = stream->GetInputStreamAt(0); auto dr = ref new DataReader(inputStream); return dr->LoadAsync(stream->Size); }).then( [](unsigned int count) { // read content txtContent->Text = content; }); } void MainPage::OnNavigatedTo(NavigationEventArgs^ e) { create_task(KnownFolders::DocumentsLibrary-> GetFileAsync(“Surface.ini")).then( [](StorageFile^ file) { return file->OpenAsync(FileAccessMode::Read); }, task_continuation_context::use_arbitrary()).then( [](IRandomAccessStream^ stream) { auto inputStream = stream->GetInputStreamAt(0); auto dr = ref new DataReader(inputStream); return dr->LoadAsync(stream->Size); }, task_continuation_context::use_arbitrary()).then( [](unsigned int count) { // read content txtContent->Text = content; }, task_continuation_context::use_current()); }
//....then([content](unsigned int count) { // read content }, task_continuation_context::use_arbitrary()).then([content]() { txtContent->Text = *content; }, task_continuation_context::use_current());
Performance Portability Coding style “It would be a mistake, and we are absolutely not telling you, to go rush out and say, 'every class I ever wrote should now be a ref class or a value class and I shouldn't use those old standard things any more” Herb Sutter //BUILD/ 2011
ArrayReference buffer(bytes, count);
Buffers (demo)
Influence future design decisions SIGN
Not a problem in practice
Platform-specific (C++/CX)Standard C++