使用无并行运行的方法 [英] Run methods in Parallel using Reactive

查看:119
本文介绍了使用无并行运行的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晕那里所有,我一直在寻找与RX架构的解决方案。我的C#4.0级会调用2个不同的方法,并节省时间,我想这样做并行。有什么办法来运行使用无框架并行2种不同的方法?不仅运行的2种方法的同时,也应该等待其他完成,合并了两个结果。示例如下图所示:

  AccountClass AC =新AccountClass();
字符串VAL1 = ac.Method1();
布尔将val2 = ac.Method2();
 

如何,我可以运行在并行运行这2种方法,并等待对方完成,合并结果一起在认购部分?

解决方案

  VAR的结果= Observable.Zip(
    Observable.Start(()=> callMethodOne()),
    Observable.Start(()=> callMethodTwo()),
    (一,二)=>新{一个,两个});

result.Subscribe(X => Console.WriteLine(x)的);
 

Halo there all, I was looking for a solution with RX framework. My C# 4.0 class is going to call 2 different methods and to save the time, I want to do it in parallel. Is there any way to run 2 different methods in parallel using Reactive Framework ? Not only run those 2 methods parallel, but also one should wait for other to complete and combine the both results. Example as shown below:

AccountClass ac = new AccountClass();    
string val1 = ac.Method1();  
bool val2 = ac.Method2();

How I can run these 2 methods run in parallel and waits each other to complete and combine the results together in the Subscription part ?

解决方案

var result = Observable.Zip(
    Observable.Start(() => callMethodOne()),
    Observable.Start(() => callMethodTwo()),
    (one, two) => new { one, two });

result.Subscribe(x => Console.WriteLine(x));

这篇关于使用无并行运行的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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