任务继续 [英] Task continuation

查看:82
本文介绍了任务继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下代码:

任务< DeviceInformationCollection ^>(DeviceInformation :: FindAllAsync(Selector,nullptr))

  ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; .then([this](DeviceInformationCollection ^ interfaces)

    {

        for_each( begin(interfaces),end(interfaces),[this](DeviceInformation ^ deviceInterface)

        {

task<DeviceInformationCollection^>(DeviceInformation::FindAllAsync(Selector, nullptr))
        .then([this](DeviceInformationCollection^ interfaces)
    {
        for_each(begin(interfaces), end(interfaces),[this](DeviceInformation^ deviceInterface)
        {

             DoSomeOperation(deviceInterface);

             DoSomeOperation(deviceInterface);

        });

 })。然后([this]()

    {

         DoAnotherOperation();

    });

        });
 }).then([this]()
  {
         DoAnotherOperation();
     });

根据任务 - 然后构造,我们是否可以确保只有在为DeviceInformation集合中的所有接口调用DoSomeOperation()之后才会调用DoAnotherOperation()?  我想要  ;只有在
内部for循环完全执行后才能调用DoAnotherOperation()。有时它按预期工作,有时不工作。在我的例子中,函数DoSomeOperation()里面还有一个task -then语句。

As per task-then construct, can we ensure that DoAnotherOperation() will be called only after DoSomeOperation() has been called for all interfaces in the DeviceInformation Collection?  I want DoAnotherOperation() to be called only after the inner for loop has been completely executed. Sometimes it works as expected and sometimes not. In my case, the function DoSomeOperation() also has a task -then statement inside it..

推荐答案

你能提供一个例子吗?你的DoSomeOperation()的实现?特别是在该方法中使用任务。

Could you provide an example of your implementation of DoSomeOperation()? Specifically the use of tasks within that method.

谢谢


这篇关于任务继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆