如何将取消的 C++/CX create_task 转换为等效的 C++/WinRT 代码?

问题描述

如何获取取消令牌源以使用等效的 C++/WinRT 代码替换下面的 create_task C++/CX 调用

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();
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)