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 8643373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:01:08+00:00 2026-06-12T12:01:08+00:00

I need to call an Async method within a method I declared. The method

  • 0

I need to call an Async method within a method I declared. The method should return a value. I’m trying to wrap calls to the Windows Store into an easy to use class. My method should look like this:

bool Purchase(enum_InAppOption optionToPurchase);

enum_InAppOption is an enum consisting of all In-App options to purchase. At some point I need to call RequestProductPurchaseAsync. The result of this call determines if the method should return trueor false. I’m new to c++/cx (or at least I have a long history between now and the last time I used c++), so maybe this is easier as I think.

The create_task looks like this:

create_task(CurrentAppSimulator::RequestProductPurchaseAsync(this->_LastProductId, false))

The options I considered / tried:

  1. returning the task would not abstract the store

  2. tried to call wait on the task. I’ve got the exception An invalid parameter was passed to a function that considers invalid parameters fatal.

  3. tried to use structured_task_group but it seems this does not allow for non void returning methods or I’m trying to provide a wrong interpretation. Compiler returns error C2064 (have googled but I can’t get the point what to change)

  4. Using an array of tasks and when_all

Found the following code on http://msdn.microsoft.com/en-us/library/dd492427.aspx#when_all in the middle of the page:

array<task<void>, 3> tasks = 
{
    create_task([] { wcout << L"Hello from taskA." << endl; }),
    create_task([] { wcout << L"Hello from taskB." << endl; }),
    create_task([] { wcout << L"Hello from taskC." << endl; })
};

auto joinTask = when_all(begin(tasks), end(tasks));

// Print a message from the joining thread.
wcout << L"Hello from the joining thread." << endl;

// Wait for the tasks to finish.
joinTask.wait();

So I tried to translate it into the following code:

array<task<Platform::String^>,1> tasks = {
    create_task(CurrentAppSimulator::RequestProductPurchaseAsync(this->_LastProductId, false))
};

Even though I included the compiler throws C2065 (‘array’: undeclared identifier), C2275 (‘Concurrency::task<_ReturnType>’: illegal use of this type as an expression and some errors that seem to be errors following up on those two.

To sum up: How to make the method return after the async task has completed, so I can return a meaningful result based on the stuff going on asynchronously?

  • 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-12T12:01:09+00:00Added an answer on June 12, 2026 at 12:01 pm

    How to make the method return after the async task has completed, so I can return a meaningful result based on the stuff going on asynchronously?

    This doesn’t make much sense: the “stuff” isn’t asynchronous if you want to wait for it to complete before returning. That’s the definition of synchronous.

    When using C++/CX, you cannot wait on a not-yet-completed task on an STA. Any attempt to do so will result in an exception being thrown. If you are going to call Purchase() on an STA and if it starts an asynchronous operation, you cannot wait for that operation to complete before returning.

    Instead, you can use .then to perform another operation when the asynchronous operation completes. If the continuation needs to be performed on the invoking thread, make sure to pass the use_current() continuation context to ensure that the continuation is executed in the correct context.

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

Sidebar

Related Questions

I call an async method which in turn calls needs to start several async
i need to call a non-static method from an async operation , for ease
I need to call a method returning a Task from within public override void
I need to call a method and pass an object from my custom UITableViewClass
I need to call a library function that sometimes won't terminate within a given
I need to call a number of different procedures within an Oracle package successively
I call a function that stacks two async calls and calls a callback when
I am learning about async/await, and ran into a situation where I need to
In iOS I need to call same method number of time, but the app
After doing an async $.ajax call, I need to highlight the table cell that

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.