c++-cx - 如何将带有取消的 C++/CX create_task 转换为等效的 C++/WinRT 代码?
问题描述
如何获取取消令牌源以将下面的 create_task C++/CX 调用替换为等效的 C++/WinRT 代码?
void MainPage::OnButtonClick(Object^ sender, RoutedEventArgs^ args)
{
MessageDialog^ msgdlg = ref new MessageDialog("Choose a color", "How To Cancel Async");
msgdlg->Commands->Append(ref new UICommand("Red", nullptr, Colors::Red));
//...
// Show the MessageDialog
cancellationTokenSource = cancellation_token_source();
task<IUICommand^> showTask = create_task(msgdlg->ShowAsync(),
cancellationTokenSource.get_token());
showTask.then([this, timer](task<IUICommand^> thisTask)
{
//...
});
}
void MainPage::OnTimerTick(Object^ sender, Object^ args)
{
cancellationTokenSource.cancel();
}
解决方案
推荐阅读
- java - SpringSession HttpSession 与 redis
- crystal-reports - 按奇数和偶数分组和排序
- android - 运行外部工具 Android Studio 时未发现错误
- python - 如何检查 PDB 中当前调试函数的返回值?
- asp.net-core - 如何在 ASP.NET Core 中编写 Request.ServerVariables["HTTP_X_FORWARDED_FOR"]?
- android - 错误:合并两个分支后找不到符号类 DataBindingComponet
- visual-studio-code - 如何在 VS Code 中配置换行缩进大小?
- android - Android 一次性设备 (COSU) 重启后无法进入 lockTaskMode
- html - IE 10 海报图像被视频标签中的源覆盖
- java - 如何在方法中模拟 this.method()?