异步操作

编程入门 行业动态 更新时间:2024-10-27 23:23:36
本文介绍了异步操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我不确定这是否是提出这个问题的正确论坛。我正在使用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

更多推荐

异步操作

本文发布于:2023-10-30 03:00:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541567.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!