使用Reactive以并行方式运行方法

Cha*_*a S 2 .net c# parallel-processing system.reactive

晕到那里,我一直在寻找RX框架的解决方案.我的C#4.0类将调用2种不同的方法并节省时间,我想并行执行.有没有办法使用Reactive Framework并行运行2种不同的方法?不仅要并行运行这两个方法,还要等待其他方法完成并合并两个结果.示例如下所示:

AccountClass ac = new AccountClass();    
string val1 = ac.Method1();  
bool val2 = ac.Method2();
Run Code Online (Sandbox Code Playgroud)

如何运行这两个方法并行运行并相互等待完成并在Subscription部分中将结果组合在一起?

Ana*_*tts 5

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

result.Subscribe(x => Console.WriteLine(x));
Run Code Online (Sandbox Code Playgroud)