Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8673431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:27:26+00:00 2026-06-12T19:27:26+00:00

I have tried looking for answer to this since three days back. It is

  • 0

I have tried looking for answer to this since three days back. It is either I have done something fundamentally wrong (that there’s an obvious mistake) or the thing is too new to have any references, I can’t seem to figure why simple cases like this would fail.

The following code uses PPL task library in C++ in a Windows Store application, simulating a file loading operation that takes 2 seconds before breaking out of the loop (of course this is to illustrate the problem with minimal codes, the real loop does other rendering to show progress, too).

The continuation part of the code (i.e. “fileLoaded = true”) never gets called if I use “use_current” as the continuation context:

bool fileLoaded = false;
while (!fileLoaded)
{
    concurrency::task<void>([this]()
    {
        // Simulate file load delay
        concurrency::wait(2000);

    }).then([this, &fileLoaded]()
    {
        fileLoaded = true; // This never gets executed!

        // If the following is changed to "use_default" or 
        // "use_arbitrary", then this continuation gets called.
    }, concurrency::task_continuation_context::use_current());

    concurrency::wait(50);
}

The same code works if I use “use_default” or “use_arbitrary”, and properly set “fileLoad” to “true”. This code can be placed anywhere in a Windows Store C++ app (e.g. Direct2D app), and it would fail (I have placed it in “DirectXPage::DirectXPage” constructor body, which I expect it to be the main UI thread). Did I do something horribly wrong?

Thanks in advance for your help! 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:27:27+00:00Added an answer on June 12, 2026 at 7:27 pm

    Since you are calling .then() on the UI thread, use_current() will cause the continuation to be scheduled for execution on the UI thread.

    However, that continuation cannot run until the UI thread is free (i.e., when it is not doing any work). But, in your example, the UI thread is never free: the DirectXPage constructor is running on the UI thread. The DirectXPage constructor will not return until the continuation executes and the continuation cannot execute until the DirectXPage constructor returns.

    You need to allow the constructor to return so that the UI thread is free to do other work (like execute the continuation).


    Also note that if you are using fileLoaded for cross-thread communication, you need to use an std::atomic<bool> or some other proper synchronization object. A simple bool is insufficient for synchronization.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have searched this web looking for an answer, but it seems that this
I have tried looking for an answer to this on other threads, but so
I have tried to answer this myself, by looking up several questions at StackOverflow.
I have tried looking though several of the already asked question about this topic
I have been looking for an answer to this for awhile and haven't found
I have tried looking at the related links and googled this, but I haven't
so I have been looking for this answer and the devise docs kind of
I've tried looking for the answer, and read many threads on this site, but
i have tried looking online but had no luck, How i could delete all
I have been looking around for solutions, and tried to implement what is often

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.