Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.