pplawait.h / experimental / resumable for co_await不起作用

时间:2017-06-16 19:07:30

标签: c++ async-await visual-studio-2017 coroutine c++20

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

建议?

1 个答案:

答案 0 :(得分:1)

在Visual Studio 2017和我使用C ++ / WinRT及其async类型函数的MFC解决方案中使用协同程序,我有以下内容。

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

首先解决方案属性中的设置。

  • 配置属性 - >一般 - >平台工具集Visual Studio 2017(v141)
  • C / C ++ - >所有选项 - >附加选项 - > / AWAIT
  • C / C ++ - >所有选项 - > C ++语言标准ISO C ++ 17标准(/ stdc ++ 17)

settings for Properties - Configuration Properties

settings for Properties - C/C++ (compiler settings)

我正在使用的实际函数的源代码(带有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.
    }
}