none
Asynchronous operation

    Question

  • I am not sure if this is the right forum to ask this question. I am working on some asynchronous operations in a C++ UWP app usig ppl. I am asking this question because I could not find many examples. My asynchronous operation is as below:

    Windows::Foundation::IAsyncOperation<bool>^MyClass::GetStatus()
    {
    
    auto myTask = create_task([this]() ->bool
    {
    ...
    ...
    if(condition)
    return true;
    else
    return false;
    });
    }

    calling it..

    IAsyncOperation<bool>^myOp = = MyClass::Instance->GeStatus();
            auto myNewTask = create_task(myOp);
           myNewTask.then([this, e](bool bStatus)
            {
    })

    On compilation it says "not all control paths return value since the bool is returned in condition only. My question is if I return the boolean value, wont the function return immediately before the task inside is completed?

    Also, in the calling section, myNewTask.then is not executed even if the the async operation returns true. What could be the reason?

    Thursday, May 23, 2019 6:52 PM

All replies

  • Hi,

    Well, from your code snippet, we still have some problem unclear. We could not reproduce it in our side. Could you please share me a Minimal, Reproducible Example about this? Just contains necessary code to reproduce the problem is enough.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, May 24, 2019 8:23 AM
    Moderator
  • Hello,

    Probably, you need to use create_async() instead of create_task() and return it. Then it would work well.

    Windows::Foundation::IAsyncOperation<bool>^MyClass::GetStatus()
    {
    	auto myTask = Concurrency::create_async([this]() ->bool
    	{
    
    		if (condition)
    			return true;
    		else
    			return false;
    	});
    	return myTask;
    }

    Saturday, May 25, 2019 7:25 PM
  • Thank you, FEC-4RP. That solved the issue !!
    Monday, May 27, 2019 6:50 AM