首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >H/ co_await的实验性/可恢复不起作用

H/ co_await的实验性/可恢复不起作用
EN

Stack Overflow用户
提问于 2017-06-17 03:07:30
回答 1查看 440关注 0票数 0

我已经在windows10.0 visual studio 2017 (版本15.2)上安装了我已经为我的项目(包括cpprestsdk)从VS2013迁移到VS2017,并使用co_await更改了.then()方法。我在网上读过一些东西,但实际上我不能再编译我的解决方案了。无法打开包含文件pplwait.h,忽略未知操作'/await‘

有什么建议吗?

EN

回答 1

Stack Overflow用户

发布于 2018-06-10 04:10:10

在Visual Studio2017中使用协程,并在MFC解决方案中使用C++/WinRT及其async类型函数,我有以下几点。

另请参阅此问题和我的答案,其中包含在concurrencystd:async和C++/WinRT中使用协程的几个示例:C++11 threads to update MFC application windows. SendMessage(), PostMessage() required?

首先,在解决方案属性中进行设置。

  • 配置属性->通用->平台工具集Visual Studio 2017 (v141)
  • C/C++ -> All Options -> Additional Options -> /await
  • C/C++ -> All Options -> C++ Language Standard ISO C++17 Standard (/stdc++17)

以及我正在使用的实际函数的源代码(带有co_await的C++/WinRT异步函数):

#include <pplawait.h>

#pragma comment(lib, "windowsapp")
#include "winrt/Windows.Foundation.h"
#include "winrt/Windows.Web.Syndication.h"

// . . .  other code

// sample function using co_await to retrieve an RSS feed which may take
// a while so we want to start it and then continue when the results are
// received. we are using one of the async functions of C++/WinRT to retrieve
// the RSS feed text. We require a pointer to a CMainFrame object which has
// the function we need to output the text lines to a displayed window.
winrt::Windows::Foundation::IAsyncAction myTaskMain(CMainFrame *p)
{
    winrt::Windows::Foundation::Uri uri(L"http://kennykerr.ca/feed");
    winrt::Windows::Web::Syndication::SyndicationClient client;
    winrt::Windows::Web::Syndication::SyndicationFeed feed = co_await client.RetrieveFeedAsync(uri);

    // send the text strings of the RSS feed list to an MFC output window for
    // display to the user.
    for (winrt::Windows::Web::Syndication::SyndicationItem item : feed.Items())
    {
        winrt::hstring title = item.Title().Text();
        p->SendMessageToOutputWnd(WM_APP, COutputWnd::OutputBuild, (LPARAM)title.c_str());  // print a string to an output window in the output pane.
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44596349

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档