根据您的问题,您有三个不同类型的集合。显然,一个人不能连接三个不同类型的流。我认为@Enigmativity's 是最正确的,但为了使其工作,您需要将其更改为:
var uiScheduler = new SynchronizationContextScheduler(SynchronizationContext.Current);
ListA = new ListA();
ListB = new ListB();
ListC = new ListC();
GetItemsA().ToObservable()
.Zip(GetItemsB().ToObservable(), (a, b) => new { a, b, })
.Zip(GetItemsC().ToObservable(), (ab, c) => new { ab.a, ab.b, c, })
.ObserveOn(uiScheduler)
.Subscribe(abc =>
{
ListA.Add(abc.a);
ListB.Add(abc.b);
ListC.Add(abc.c);
});
另一种解决方案可能是:
var a = Observable.Start(() => GetListA());
var b = Observable.Start(() => GetListB());
var c = Observable.Start(() => GetListC());
a.Zip(b, c, (x, y, z) => Tuple.Create(x, y, z))
.ObserveOn(uiScheduler)
.Subscribe(result =>
{
ListA = result.Item1;
ListB = result.Item2;
ListC = result.Item3;
});
我希望在创建集合后立即收集:
a.ObserveOn(uiScheduler)
.Do(l => ListA = l)
.Zip(b, (la, lb) => lb)
.ObserveOn(uiScheduler)
.Do(l => ListB = l)
.Zip(c, (lb, lc) => lc)
.ObserveOn(uiScheduler)
.Subscribe(listc => ListC = listc);