在Task.Factory.ContinueWhenAll方法中传递参数 [英] Passing Parameter in Task.Factory.ContinueWhenAll method

查看:666
本文介绍了在Task.Factory.ContinueWhenAll方法中传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我想将参数(Command3)传递给完成依赖任务(task1和task2)后创建的Task。

I want to pass the parameter(Command3) to a Task which is created after completing the dependent tasks (task1 and task2).

        Task[] tasks = { task1, task2 };
        ICommand command3 = new TestCommand3();
        Task task3 = Task.Factory.ContinueWhenAll(tasks, (setOfTasks) =>
        {
            Console.WriteLine("Task3");
        });



我确实看到Task.Factory.StartNew和ContinueWith方法有该选项,并且看不到ContinueWhenAll和ContinueWhenAny方法中的参数传递选项。

I do see the Task.Factory.StartNew and ContinueWith methods has that option and don't see parameter passing option available in ContinueWhenAll and ContinueWhenAny methods.


 不确定为什么没有提供选项参数选项和  想知道是否还有其他更好的解决方法选项。

推荐答案

您是否尝试过访问
command3 ContinueWhenAll 的主体

Have you tried to access command3 in the body of ContinueWhenAll?


这篇关于在Task.Factory.ContinueWhenAll方法中传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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