Skip to content

Instantly share code, notes, and snippets.

@heejune
Created February 2, 2017 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heejune/0dcce4aefd3a83eed9a60e7340a9a6e7 to your computer and use it in GitHub Desktop.
Save heejune/0dcce4aefd3a83eed9a60e7340a9a6e7 to your computer and use it in GitHub Desktop.
Demo registers Progress handler from IAsyncOperationWithProgress
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