我不确定这是否是提出这个问题的正确论坛。我正在使用C ++ UWP app usig ppl进行一些异步操作。我问这个问题,因为我找不到很多例子。我的异步操作如下:
Windows :: Foundation :: IAsyncOperation< bool> ^ MyClass :: GetStatus() { auto myTask = create_task([this]() - > bool { ... ... if(condition)返回true ; else 返回false; }); }调用它..
IAsyncOperation< bool> ^ myOp = = MyClass ::实例 - > GeStatus(); auto myNewTask = create_task(myOp); myNewTask.then([this,e](bool bStatus) {})编译时说"不是全部"控制路径返回值,因为bool仅在条件下返回。我的问题是,如果我返回布尔值,在内部任务完成之前函数不会立即返回吗?
此外,在调用部分,即使myNewTask.then也未执行async操作返回true。 可能是什么原因?
解决方案
<嗯,从你的代码片段中,我们仍然有一些问题不清楚。我们无法在我们这边重现它。能否请您分享一个关于此的最小,可重复的例子?只需包含重现问题的必要代码就足够了。
祝你好运,
Roy
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?
解决方案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
更多推荐
异步操作
发布评论