Microsoft
Visual Studio
Visual Studio
  • Home
    • Problems
    • Suggestions
  • Downloads
    • Visual Studio IDE
    • Visual Studio Code
    • Azure DevOps
    • Team Foundation Server
    • Accounts and Subscriptions
  • Subscriber Access
      • Microsoft 365
      • Azure
      • Office 365
      • Dynamics 365
      • SQL
      • Windows 10
      • Windows Server
      • Enterprise Mobility + Security
      • Power BI
      • Teams
      • Visual Studio
      • Surface for Business
      • AI
      • Internet of Things
      • Azure Cognitive Services
      • Quantum
      • Research
      • Docs
      • TechNet
      • Developer Network
      • Windows Dev Center
      • Windows IT Pro Center
      • FastTrack
      • Partner Network
      • Solution Providers
      • Partner Center
      • Cloud Hosting
      • Education
      • Financial services
      • Government
      • Health
      • Manufacturing & resources
      • Retail
      • Security
      • Licensing
      • AppSource
      • Azure Marketplace
      • Events
    • View all
    Sign in

    Developer Community

    Get help from our community supported forum
    • Home /
    • Visual Studio /
    Searched and didn’t find your feedback?
    • Visual Studio
    • Visual Studio for Mac
    • .NET
    • C++
    • Azure DevOps
    • TFS
    or
    • Visual Studio
    • Visual Studio for Mac
    • .NET
    • C++
    • Azure DevOps
    • TFS
    Visual Studio
    Visual Studio for Mac
    .NET
    C++
    Azure DevOps
    TFS
    3

    co_await trashes lambda captures

    windows 10.0visual studio 2017 rc

    avatar image Hamza Sood reported Dec 05, 2016 at 06:19 PM

    thub.nodes.view.add-new-comment
    Add comment Show 2

    Add Comment

    10 |10000 characters needed characters left characters exceeded
    avatar image Hamza Sood · Dec 05, 2016 at 06:25 PM 0
    Share
    avatar image Leo Zhang [MSFT] · Sep 07, 2017 at 02:34 AM 0
    Share

    Solutions

    · Add your solution
    1

    Solution by avatar image Gor Nishanov [MSFT] · Aug 25, 2017 at 05:37 PM

    In this case, the operator() of lambda object outlives the lifetime of the lambda object that stores captured variables.

    To make this code work, make your lambda stateless by avoiding capturing any variables and passing the desired values as arguments instead. Something like this:

    int testNumber = 3; 
    auto testBlock = [](auto testNumber) -> concurrency::task<void> { ... };
    testBlock(testNumber);
    
    thub.nodes.view.add-new-comment
    Add comment · Share

    Add Comment

    10 |10000 characters needed characters left characters exceeded

    Add a Solution

    Up to 5 attachments (including images) can be used with a maximum of 2.1 GB each and 2.1 GB total.

    Follow

    53 People are following this

    Related Problems

    Pyvot Pywin32 download experience is bad
    1 Solution

    how set php tools ?
    0 Solution

    Asp.Net Core Project "Host in cloud" checkbox is missing.
    0 Solution

    向项目添加SharedProject 会使VS 停止响应->Add SharedProject to your project will enable VS to stop responding
    0 Solution

    python command prompt exits immediately
    1 Solution

    Cannot start performance profiler
    1 Solution

    Platform dependant project loading
    0 Solution

    Crash When Moving and Renaming a File
    1 Solution

    C++ go to include file failing
    0 Solution

    VS 2017 hangs every time i try to update all nuget packages
    1 Solution

    What's new

    • NEW Surface Pro 6
    • NEW Surface Laptop 2
    • NEW Surface Go
    • Xbox One X
    • Xbox One S
    • VR & mixed reality
    • Windows 10 apps
    • Office apps

    Store & Support

    • Account profile
    • Download Center
    • Sales & support
    • Returns
    • Order tracking
    • Store locations
    • Support
    • Buy online, pick up in store

    Education

    • Microsoft in education
    • Office for students
    • Office 365 for schools
    • Deals for students & parents
    • Microsoft Azure in education

    Enterprise

    • Microsoft Azure
    • Enterprise
    • Data platform
    • Find a solution provider
    • Microsoft partner resources
    • Microsoft AppSource
    • Manufacturing & resources
    • Financial services

    Developer

    • Microsoft Visual Studio
    • Windows Dev Center
    • Developer Network
    • TechNet
    • Microsoft developer program
    • Channel 9
    • Office Dev Center

    Company

    • Careers
    • About Microsoft
    • Company news
    • Privacy at Microsoft
    • Investors
    • Diversity and inclusion
    • Accessibility
    • Security
    English (United States)
    • Sitemap
    • Contact us
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2018
    • Anonymous
    • Sign in
    • Spaces
    • Visual Studio
    • Visual Studio for Mac
    • .NET
    • C++
    • Azure DevOps
    • TFS
    • Explore
    • Topics
    • Problems
    • Features
    • Users
    • Badges