Created
February 2, 2017 15:13
-
-
Save heejune/0dcce4aefd3a83eed9a60e7340a9a6e7 to your computer and use it in GitHub Desktop.
Demo registers Progress handler from IAsyncOperationWithProgress
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
void WebCrawlerSample::MainPage::button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) | |
{ | |
HttpClient^ client = ref new HttpClient(); | |
Uri^ addr = ref new Uri("https://heejune.me"); | |
auto asyncOp = client->GetAsync(addr); | |
// create and set Progress handler | |
asyncOp->Progress = ref new AsyncOperationProgressHandler<HttpResponseMessage^, HttpProgress>( | |
[=](IAsyncOperationWithProgress<HttpResponseMessage^, HttpProgress>^ pretask, HttpProgress progressInfo) { | |
// access ui element | |
Windows::ApplicationModel::Core::CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync( | |
CoreDispatcherPriority::Normal, | |
ref new Windows::UI::Core::DispatchedHandler([this, progressInfo]() { | |
textBlock->Text += progressInfo.BytesReceived.ToString() + "\n"; | |
})); | |
}); | |
auto task = create_task(asyncOp); | |
// get result | |
task.then([=](HttpResponseMessage ^ msg) { | |
// access ui element | |
Windows::ApplicationModel::Core::CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync( | |
CoreDispatcherPriority::Normal, | |
ref new Windows::UI::Core::DispatchedHandler([this, msg]() { | |
textBlock->Text += msg->StatusCode.ToString(); | |
})); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment